CIRCULAR LINKED LIST IN DATA STRUCTURES CLL

sharikacs1 13 views 26 slides Sep 26, 2024
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

Circular linked list IN DATA STRUCTURES


Slide Content

Circular Linked List
single linked list - link field of the last node is
null.
circular linked list - link field of the last node
holds
the address of the first node.
HEA
D
1 2 3

Singly linked list
1 2
3X

Singly Circular linked list
1 2 3

Doubly linked
list
5
HEA
D
X1 X9

Doubly Circular linked
list
5
HEA
D
1 9

insertio
n

Singly Circular linked list – insert at front/end
Current=head
While(current.link!
=head)
Current=current.link
EndWhile
Current.link=newnode
Newnode.link=head
Head=newnode
1 2 3
HEA
D
curren
t

Singly Circular linked list – insert at front/end
Current=hea
d
While(current.link!
=head)
Current=current.link
EndWhile
Current.link=newno
de
Newnode.link=head
Head=newnode
1 2 3
HEA
D
curren
t
5
newnod
e
HEA
D

Insertion at the front/end
Algorithm
CIRCULAR_ADD_FRONT_END
(item)
Input: Header is the pointer to the front
of the circular list
Output: Item inserted at the front/end of the
list
Data Structure: Linked
list.
Steps
:
1.
2.
3.
4.
1.
2.
3.
5.
1.
2.
Newnode=malloc(node)
Newnode.data=item
Newnode.link=NULL
If(head=NULL)
Head=newnode
Newnode.link=newnode
Exit
Else
Current=head
While(current.link!=head)
1
.
Current=current.li
nk EndWhile
Current.link=newnod
e Newnode.link=head
Head=newnode
EndIf Stop
3.
4.
5.
6.
6.
7.

deletio
n

Singly Circular linked list – delete from front
Current=head Do
Prev=current
Current=current.link
While(current!
=head)
1 2 3
HEAD
curren
t

Singly Circular linked list – delete from front
Current=head Do
Prev=current
Current=current.link
While(current!
=head)
1 2 3
HEA
D
curren
t
pre
v

Singly Circular linked list – delete from front
Current=head Do
Prev=current
Current=current.link
While(current!
=head)
1 2 3
HEA
D
curren
t
pre
v

Singly Circular linked list – delete from front
Current=head Do
Prev=current
Current=current.link
While(current!
=head)
1 2 3
HEA
D
curre
nt
pre
v

Singly Circular linked list – delete from
front
Prev.link=current.link Head=head.link FREE (current)
1 2 3
HEA
D
curre
nt
pre
v

Singly Circular linked list – delete from
front
Prev.link=current.link Head=head.link FREE (current)
1 2 3
HEA
Dcurren
t
pre
v

Singly Circular linked list – delete from
front
Prev.link=current.link Head=head.link FREE (current)
1 2 3
HEA
Dcurren
t
pre
v

Singly Circular linked list – delete from
front
Prev.link=current.link Head=head.link FREE (current)
1 2 3
HEA
D
pre
v

Deletion from the front
Algorithm
CIRCULAR_DELETE_FRO
NT ()
Input: Header is the
pointer to the front of
the circular list
Output: Item deleted
from the front /end of
the list
Data Structure: Linked
list.
Steps
:
1.If(head=NULL)
1.Print(“List Empty”)
2.Exit
2.Else If( head.link=head)
1.Item=head.data
2.FREE (head)
3.Head=NULL
3.Else
1.Current=head
2.Do Prev=current
2.Current=current.link
3.While(current!=head)
4.Prev.link=current.link
5.Head=head.link
6.FREE (current)
1
.
4.EndI
f
5.Stop

Singly Circular linked list – delete from end
Current=head
While(current.link!
=header)
Prev=current
Current=current.link
EndWhile
1 2 3
HEA
D
curre
nt
prev

Singly Circular linked list – delete from end
Current=head
While(current.link!
=header)
Prev=current
Current=current.link
EndWhile
1 2 3
HEA
D
curren
t
pre
v

Singly Circular linked list – delete from
end
Prev.link=head FREE (current)
1 2 3
HEA
D
curren
t
pre
v

Singly Circular linked list – delete from
end
Prev.link=head FREE (current)
1 2 3
HEA
D
curren
t
pre
v

Singly Circular linked list – delete from end
Prev.link=head FREE (current)
1 2
HEA
D
pre
v

Deletion from the end
Algorithm
CIRCULAR_DELETE_END ()
Input: Header is the pointer to
the front of the circular list
Output: Item deleted from the
end of
the list
Data Structure: Linked list.
Steps
:
1.If(head=NULL)
1.Print(“List is Empty”)
2.Exit
2.Else If( head.link=head)
1.Item=head.data
2.FREE (head)
3.Head=NULL
4.Exit
3.Else
1.Current=head
2.While(current.link!
=head)
Prev=current
2.Current=current.link
1.EndWhile
2.Prev.link=head
3.FREE (current)
1
.
4.EndI
f
5.Stop
Tags