21
June 6, 2022 Nikitha 1 Doubly circular link list…. NIKITHA B CHOUDHARY 3 rd sem, cse Jnnce ,Shimoga

My Linked List Ppt

Embed Size (px)

Citation preview

Page 1: My Linked List Ppt

April 9, 2023 Nikitha 1

Doubly circular link list….

NIKITHA B CHOUDHARY 3rd sem, cse Jnnce ,Shimoga

Page 2: My Linked List Ppt

April 9, 2023 Nikitha 2

Contents : Types of linked list

Disadvantages of singly linked list Doubly linked listCircular linked listDrawbacks of singly circular linked listHeader nodeInsert a node at the front end and rear

endDelete a node at the front end and rear

endDelete a node whose information is

specifiedInsert a node after the keyInsert a node before the keyAdvantages of doubly linked list Disadvantages of doubly linked list

Page 3: My Linked List Ppt

April 9, 2023 Nikitha 3

Singly linked list

Doubly linked list

Singly circular linked list

Doubly circular linked list

tail

TYPES OF LINKED LIST

NIKITHA
Page 4: My Linked List Ppt

April 9, 2023 Nikitha 4

Disadvantages of singly linked list

Using singly linked list it is not possible to traverse the list backwards.

Insertion/Deletion to a node to the left of the desired node is difficult.

It requires finding the predecessor which takes more time.

Due to this disadvantages of singly linked list doubly linked list came into existence…..

Page 5: My Linked List Ppt

April 9, 2023 Nikitha 5

Doubly link list.. (Two way list)

Allow sequential access to the list in both directions Each node points to

Next node Previous node

Each node is divided into three parts

Info

Llink(Prev) ie.,Predecessor

Rlink(Next) ie.,Successor

.info

next

prev info next

Page 6: My Linked List Ppt

April 9, 2023 Nikitha 6

Circular link list

A Circular Linked List is a special type of Linked List The next field of the last node contains a pointer, it points back

to the first node.. The drawbacks of linear linked list made way to circular linked

list..

Circular linked list

1.Singly circular linked list 2.Doubly circular linked list

Each of these linked list can be with header node and without header node..

Page 7: My Linked List Ppt

April 9, 2023 Nikitha 7

Circular linked list had advantages over a linear list , but it still had several drawbacks..

They are overcomed by doubly linked list ..

Drawbacks of singly circular linked list :

[1] We cannot traverse in the backward direction

[2] A node cannot be deleted from a circularly linked list, given only a pointer to that node.

Page 8: My Linked List Ppt

April 9, 2023 Nikitha 8

This is circular doubly link list….

20 3010 40

info next prev info next prev info next prev info next prev info

50

A circular doubly linked list

first node last node

Page 9: My Linked List Ppt

April 9, 2023 Nikitha 9

Header node:

To minimize the number of checking for various cases, the Header Node is used.

The info field of the header node usually contains the number of nodes in the list.

10 204 30

llink info rlink llink info rlink llink info rlink llink info rlink llink info

rlink

40

first node last node

Circular Doubly Linked List With A Header Node

header node

Page 10: My Linked List Ppt

April 9, 2023 Nikitha 10

An empty circular link list with Header Node:

head

llink rlink

Here the link field of the header node contains the address of itself..

So,

if (head rlink == head)

{

printf (“List is empty\n”);

return head;

}

Page 11: My Linked List Ppt

April 9, 2023 Nikitha 11

Insert A Node At The Front End :

cur

3head 20 30 40

10

temp

Cur =head rlink

head rlink==temp;

temp llink==head;

temp rlink==cur;

cur llink==temp;

Page 12: My Linked List Ppt

April 9, 2023 Nikitha 12

Insert A Node At The Rear End :

3

head

10 20 30 40

cur

temp

Cur =head rlink

head llink==temp;

temp rlink==head;

temp llink==cur;

cur rlink==temp;

Page 13: My Linked List Ppt

April 9, 2023 Nikitha 13

Delete A Node From The Front End :

cur

3head 10 20 30

next

cur=head rlink;

next=cur rlink;

head rlink==next;

next llink=head;

printf (“The deleted item is %d \n”, cur info);

freenode (cur);

Page 14: My Linked List Ppt

April 9, 2023 Nikitha 14

Delete A Node From The Rear End :

3head 10 20 30

prev

cur=head llink;

prev=cur llink;

head llink==prev;

prev rlink=head;

printf (“The deleted item is %d \n”, cur info);

freenode (cur);

cur

Page 15: My Linked List Ppt

April 9, 2023 Nikitha 15

Delete A Node Whose information is specified :

prev

3head 10 20 30

cur

cur=head rlink;

while (cur!=head)

{ if (item==cur info) break;

cur=cur rlink; }

if (cur ==head)

{printf (“Item not found\n”); return head; }

prev=cur llink; next==cur rlink;

prev rlink=next; next llink=prev;

freenode (cur);

next

Page 16: My Linked List Ppt

April 9, 2023 Nikitha 16

Insert A Node After The Key :

4

head

10 20 30 40

next

50

temp

cur

Page 17: My Linked List Ppt

April 9, 2023 Nikitha 17

cur=head rlink;

while (cur!=head)

{ if (item==cur info) break;

cur=cur rlink; }

if (cur ==head)

{ printf (“Key not found\n”); return head;

}

next=cur rlink;

printf (“Item to be inserted to right of %d=“,item);

temp= getnode();

scanf (“% d”,& temp info);

cur rlink=temp;

temp link=cur;

next llink=temp;

temp rlink=next;

return head;

Page 18: My Linked List Ppt

April 9, 2023 Nikitha 18

Insert A Node Before The Key :

4

head

10 20 30 40

50

temp

curprev

Page 19: My Linked List Ppt

April 9, 2023 Nikitha 19

Advantages Of Doubly Linked List :

Using Doubly Linked List with a header node many problems can be solved very easily and efficiently.

They are extensively used in trees. Graphs can be represented using doubly

linked list.

Page 20: My Linked List Ppt

April 9, 2023 Nikitha 20

Disadvantages of doubly circular linked list :

[1] Each node in the list requires two links, rlink and llink which requires additional storage for each field.

[2] During manipulation care has to be taken to manipulate both the links.

Page 21: My Linked List Ppt

April 9, 2023 Nikitha 21

Thank You...………!!!!For listening

Have A Nice Day...........

“Don’t be like a blind bat that wings its silent flight under the cover of darkness, but be like a majestic eagle that

flies towards the sun...............!!”