Lecture - 4 - Circular Linked List in Data Structure
Lecture - 4 - Circular Linked List in Data Structure
14 100 35 200 20 N
400 100 200
After inserting:
14 100 35 200 20 N
75 400
400 100
200
Delete a node from the list: before deletion:
35 300 46 500 30 N
200 300 500
In circular linked list we have three
functions. They are
• addcirq( )
• delcirq( )
• cirq_display( )
addcirq( ) :-
This function accepts three
parameters.
First parameter receives the
address of the first node.
The second parameter receives
the address of the pointer to the last
node.
Delcirq( ) :-
• This function receives two parameters.
The first parameter is the pointer to the front no
The second is the pointer to the rear.
front rear
10 17 16 5
OPERATIONS ON LINKED LISTS
start
node1 node2
node3
DELETING A PARTICULAR NODE
node1 node3
node2
To be deleted
SEARCHING
Searching involves finding the required element in the
list
We can use various techniques of searching like linear
search or binary search where binary search is more
efficient in case of Arrays
But in case of linked list since random access is not
available it would become complex to do binary search
in it
We can perform simple linear search traversal
In linear searcheach node is
traversed till the data in the node matches
with the required value
REVERSING A LINKED
LIST
• We can reverse a linked list by reversing the
direction of the links between 2 nodes
Applications of linked list in
computer science
• Implementation of stacks and queues
• Implementation of graphs : Adjacency list representation of graphs
is most popular which is uses linked list to store adjacent vertices.
• Dynamic memory allocation : We use linked list of free blocks.
• Maintaining directory of names
• Performing arithmetic operations on long integers
• Manipulation of polynomials by storing constants in the node of
linked list representing sparse matrices
Applications of linked list in real
world
• Image viewer – Previous and next images are linked, hence can be
accessed by next and previous button.
• Previous and next page in web browser – We can access previous
and next url searched in web browser by pressing back and next
button since, they are linked as linked list.
• Music Player – Songs in music player are linked to previous and next
song. you can play songs either from starting or ending of the list.
Applications of circular linked
• Useful for implementation of queue. Unlike this 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.
• 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.
• Circular Doubly Linked Lists are used for implementation of advanced data structures like
Fibonacci Heap.