[prev] 65 [next]

Iteration over Linked Lists

When manipulating list elements
  • typically have pointer p to current node
  • to access the data in current node:   p.value
  • 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)