[   ^ to index...   |   <-- previous   ]

Variations on the list

Doubly linked lists

One other important variation on linked lists is to have list nodes point both to the next and the previous element. Among other things, this makes it easy to traverse a list backwards:

struct ListNode { int value; ListNode * next, *prev; }; class LinkedList { // some stuff, then: private: ListNode * head, * last; }; // Reverse traversal void List::printReverseOrder() { ListNode * current = last; while (current != NULL) { cout << current->value << endl; current = current->prev; } }

Last modified: Wed Jul 12 19:35:05 PDT 2000