Circularly Linked Lists Lecture 23 Wed, Mar 22, 2006
Topics Circularly linked lists The CircLinkedList class Evaluation of List implementations
Circularly Linked Lists A circularly linked list is a doubly linked list in which one additional node is allocated. Its next and prev pointers are the head and tail pointers of the list. Its data member is not used.
The Data Members A CircLinkedList object has two data members: int size - Number of elements in the list. DoublyLinkedListNode* list - Pointer to the extra (dummy) node.
Circularly Linked List Nodes A CircularlyLinkedList uses DoublyLinkedListNodes. The dummy node is always allocated – even in an empty list.
Benefits of this Implementation The next pointer of the last node points to the dummy node, so it is not null. The prev pointer of the first node points to the dummy node, so it is not null. In fact, none of the pointers in the structure is null. Since there are no null pointers, the code in the member functions contains no special cases!
The CircLinkedList Class doublylinkedlistnode.h circlinkedlist.h ListTest.cpp