Presentation is loading. Please wait.

Presentation is loading. Please wait.

Circularly Linked Lists

Similar presentations


Presentation on theme: "Circularly Linked Lists"— Presentation transcript:

1 Circularly Linked Lists
Lecture 23 Wed, Mar 22, 2006

2 Topics Circularly linked lists The CircLinkedList class
Evaluation of List implementations

3 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.

4 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.

5 Circularly Linked List Nodes
A CircularlyLinkedList uses DoublyLinkedListNodes. The dummy node is always allocated – even in an empty list.

6 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!

7 The CircLinkedList Class
doublylinkedlistnode.h circlinkedlist.h ListTest.cpp


Download ppt "Circularly Linked Lists"

Similar presentations


Ads by Google