Traversing a linked list in C++ : Linked List – 2
February 11, 2011 Leave a comment
Question. We wish to traverse (and print the data) in a singly linked list.
One could proceed as follows:
void traverse ( Node *head)
Node *curr = head;
while ( ! curr)
cout << curr->data << endl;
curr = curr -> next;
Traversal takes time linear in the length of the list.