0% found this document useful (0 votes)
4 views18 pages

L7-Revised - Doubly and Circular Linked Lists

The document discusses linked lists, specifically focusing on singly, doubly, and circular linked lists. It explains the structure and operations of doubly linked lists, including insertion and deletion processes, as well as the advantages of circular linked lists for traversal and queue implementation. Overall, it highlights the flexibility and efficiency of linked lists compared to fixed-size arrays.

Uploaded by

xiy29440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views18 pages

L7-Revised - Doubly and Circular Linked Lists

The document discusses linked lists, specifically focusing on singly, doubly, and circular linked lists. It explains the structure and operations of doubly linked lists, including insertion and deletion processes, as well as the advantages of circular linked lists for traversal and queue implementation. Overall, it highlights the flexibility and efficiency of linked lists compared to fixed-size arrays.

Uploaded by

xiy29440
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Doubly and

Circular Linked
Lists
SINGLY LINKED LIST.
RECAP TO GO FORWARD.

 The node at the beginning is called the head of the list


 The entire list is identified by the pointer to the head node,
this pointer is called the list head.
 Nodes can be added or removed from the linked list during
execution
 Addition or removal of nodes can take place at beginning,
end, or middle of the list
 Linked lists can grow and shrink as needed, unlike arrays,
which have a fixed size.
TYPES OF LISTS.

 Depending on the way in which the links are used to


maintain adjacency, several different types of linked lists
are possible.
 Singly Linked List
 Doubly Linked List
 Circular Linked List
DOUBLY LINKED LIST.

 Recall, deletion of element in singly linked list required


link hopping to find last node(tail node).
 Made easier with doubly linked list.
DOUBLY LINKED LIST.

 Is a linked list structure in which each node has a pointer


to both its successor and its predecessor.
 Pointers exist between adjacent nodes in both directions.
 The list can be traversed either forward or backward.
 There are three pieces of metadata in the head structure :
a count, a position pointer for traversals, and a rear
pointer.
DOUBLY LINKED LIST.

 Although a rear pointer is not required in all doubly linked


lists, it makes some of the list algorithms, such as insert and
search, more efficient.
 Each node contains two pointers: a backward pointer to its
predecessor and a forward pointer to its successor.
DOUBLY LINKED LIST - INSERTION.
 Insertion follows the basic
pattern of inserting a node into
a singly linked list, but we also
need to connect both the
forward and the backward
pointers.
 A null doubly linked list’s head
and rear pointers are null.
 To insert a node into a null list,
we simply set the head and
rear pointers to point to the
new node and set the
forward and backward
pointers of the new node to
null.
DOUBLY LINKED LIST - DELETION.
 Deletion of nodes:

 Deleting requires that the


deleted node’s predecessor,
if present, be pointed to the
deleted node’s successor
and that the successor, if
present, be set to point to
the predecessor.
 Once we locate the node to be
deleted, we simply change its
predecessor’s and successor’s
pointers and recycle the node
CIRCULAR LINKED LIST.
A circular linked list can be a singly linked list or a doubly linked list.
head

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.

You might also like