Iteration over Linked Lists
When manipulating list elements
- typically have pointer
p to current node (NodeT *p )
- to access the data in current node:
p->data
- to get pointer to next node:
p->next
To iterate over a linked list:
- set
p to point at first node (head)
- examine node pointed to by
p
- change
p to point to next node
- stop when
p reaches end of list (NULL )
|