L7-Revised - Doubly and Circular Linked Lists
L7-Revised - Doubly and Circular Linked Lists
Circular Linked
Lists
SINGLY LINKED LIST.
RECAP TO GO FORWARD.
A B C
In singly linked list, pointer from the last element in the list points back
to the first element
CIRCULAR LINKED LIST.
A circular linked list can be a singly linked list or a doubly linked list.
In a doubly circular linked list, the previous pointer of the first node
is connected to the last node while the next pointer of the last node is
connected to the first node.
CIRCULAR LINKED LIST.
Circularly linked lists are primarily used in lists that allow access
to nodes in the middle of the list without starting at the beginning.
Insertion into and deletion from a circularly linked list follow the same
logic patterns used in a singly linked list except that the last node
points to the first node. So, when inserting or deleting the last node, in
addition to updating the rear pointer in the header, the link field must
point to the first node.
Advantages of Circular Linked Lists:
1. Any node can be a starting point. We can traverse the whole list by starting from any point. We just need to stop
when the first visited node is visited again.
2. Useful for implementation of queue. Unlike usual implementation, we don’t need to maintain two pointers for
front and rear if we use circular linked list. We can maintain a pointer to the last inserted node and front can
always be obtained as next of last.
3. Circular lists are useful in applications to repeatedly go around the list. For example, when multiple
applications are running on a PC, it is common for the operating system to put the running applications on a list
and then to cycle through them, giving each of them a slice of time to execute, and then making them wait while
the CPU is given to another application. It is convenient for the operating system to use a circular list so that
when it reaches the end of the list it can cycle around to the front of the list.
17
The end.