[prev] [index] [next]

Exercise: Length of List

Write a function that will
  • given a pointer to the first node in the list:
  • return a count of the number of nodes in the list
  • return zero if the list is empty
Use the following function interface:

int length(NodeT *list) { ... }

Recall: 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)