SlideShare a Scribd company logo
1 of 37
© Oxford University Press 2011. All rights reserved.
Data Structures Using CData Structures Using C
Reema TharejaReema Thareja, Assistant Professor, Institute of
Information Technology and Management,
New Delhi
© Oxford University Press 2011. All rights reserved.
CHAPTER 8
LINKED LISTS
© Oxford University Press 2011. All rights reserved.
INTRODUCTION
• A linked list in simple terms is a linear collection of data elements. These data
elements are called nodes.
• Linked list is a data structure which in turn can be used to implement other data
structures. Thus, it acts as building block to implement data structures like
stacks, queues and their variations.
• A linked list can be perceived as a train or a sequence of nodes in which each
node contain one or more data fields and a pointer to the next node.
1 2 3 4 5 6 7 X
START
In the above linked list, every node contains two parts- one integer and
the other a pointer to the next node. The left part of the node which
contains data may include a simple data type, an array or a structure.
The right part of the node contains a pointer to the next node (or address
of the next node in sequence). The last node will have no next node
connected to it, so it will store a special value called NULL.
© Oxford University Press 2011. All rights reserved.
INTRODUCTION contd.
• Linked list contains a pointer variable, START which stores the address
of the first node in the list.
• We can traverse the entire list using a single pointer variable START.
The START node will contain the address of the first node; the next part
of the first node will in turn store the address of its succeeding node.
• Using this technique the individual nodes of the list will form a chain of
nodes. If START = NULL, this means that the linked list is empty and
contains no nodes.
• In C, we will implement a linked list using the following code:
• struct node
• {
• int data;
• struct node *next;
• };
© Oxford University Press 2011. All rights reserved.
1 DATA
NEXT
H 4
E 7
L 8
L 10
O -1
1
2
3
4
5
6
7
8
9
10
START
START pointing
to the first
element of the
linked list in
memory
9
AVAIL
If we want to add a node to an already existing
linked list in the memory, we will first find any free
space in the memory and then use it to store the
information.
The operating system maintains a free pool which is
a linked list of a of all free memory cells. It maintains
a pointer variable AVAIL which stores the address of
the first free space.
When you delete a node from the linked list, the
operating system adds the freed memory to the free
pool.
The operating system will perform this operation
whenever it finds the CPU idle or whenever the
programs are falling short of memory. The operating
system scans through all the memory cells and mark
the cells that are being used by some or the other
program. Then, it collects all those cells which are
not being used and add their address to the free pool
so that it can be reused by the programs. This
process is called garbage collection. The whole
process of collecting unused memory cells (garbage
collection) is transparent to the programmer.
© Oxford University Press 2011. All rights reserved.
Singly Linked List
• A singly linked list is the simplest type of linked list in which every node
contains some data and a pointer to the next node of the same data
type. By saying that the node contains a pointer to the next node we
mean that the node stores the address of the next node in sequence.
1 2 3 4 5 6 7 X
START
Algorithm for traversing a linked list
Step 1: [INITIALIZE] SET PTR = START
Step 2: Repeat Steps 3 and 4 while PTR != NULL
Step 3: Apply Process to PTR->DATA
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: EXIT
© Oxford University Press 2011. All rights reserved.
Algorithm to print the information stored in each node of the linked list
Step 1: [INITIALIZE] SET PTR = START
Step 2: Repeat Steps 3 and 4 while PTR != NULL
Step 3: Write PTR->DATA
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: EXIT
Algorithm to print the number of nodes in the linked list
Step 1: [INITIALIZE] SET Count = 0
Step 2: [INITIALIZE] SET PTR = START
Step 3: Repeat Steps 4 and 5 while PTR != NULL
Step 4: SET Count = Count + 1
Step 5: SET PTR = PTR->NEXT
[END OF LOOP]
Step 6: EXIT
© Oxford University Press 2011. All rights reserved.
Algorithm to search an unsorted linked list
Step 1: [INITIALIZE] SET PTR = START
Step 2: Repeat Steps 3 while PTR != NULL
Step 3: IF VAL = PTR->DATA
SET POS = PTR
Go To Step 5
ELSE
SET PTR = PTR->NEXT
[END OF IF]
[END OF LOOP]
Step 4: SET POS = NULL
Step 5: EXIT
1 7 3 4 2 6 5 X
PTR
1 7 3 4 2 6 5 X
PTR
1 7 3 4 2 6 5 X
PTR
1 7 3 4 2 6 5 X
PTR
© Oxford University Press 2011. All rights reserved.
1 7 3 4 2 6 5 X
START
START
Algorithm to insert a new node in the beginning of the linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 7
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = START
Step 6: SET START = New_Node
Step 7: EXIT
9 1 7 3 4 2 6 5 X
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node at the end of the linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 10
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = NULL
Step 6: SET PTR = START
Step 7: Repeat Step 8 while PTR->NEXT != NULL
Step 8: SET PTR = PTR ->NEXT
[END OF LOOP]
Step 9: SET PTR->NEXT = New_Node
Step 10: EXIT
1 7 3 4 2 6 5 X
START, PTR
1 7 3 4 2 6 5 9 X
PTRSTART
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node after a node that has value NUM
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 12
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET PTR = START
Step 6: SET PREPTR = PTR
Step 7: Repeat Step 8 and 9 while PREPTR->DATA != NUM
Step 8: SET PREPTR = PTR
Step 9: SET PTR = PTR->NEXT
[END OF LOOP]
Step 10: PREPTR->NEXT = New_Node
Step 11: SET New_Node->NEXT = PTR
Step 12: EXIT
51 7 3 4 2 6 X
START, PTR, PREPTR
1 7 3 4 2 6 5 X
START PREPTR PTR
1 7 3 9 4 2 6 5 X
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the first node from the linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 5
[END OF IF]
Step 2: SET PTR = START
Step 3: SET START = START->NEXT
Step 4: FREE PTR
Step 5: EXIT
1 7 3 4 2 6 5 X
7 3 4 2 6 5 X
START
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the last node of the linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 and 5 while PTR->NEXT != NULL
Step 4: SET PREPTR = PTR
Step 5: SET PTR = PTR->NEXT
[END OF LOOP]
Step 6: SET PREPTR->NEXT = NULL
Step 7: FREE PTR
Step 8: EXIT
1 7 3 4 2 6 5 X
START, PREPTR, PTR
1 7 3 4 2 6 X 5 X
PREPTR PTRSTART
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the node after a given node from the linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 10
[END OF IF]
Step 2: SET PTR = START
Step 3: SET PREPTR = PTR
Step 4: Repeat Step 5 and 6 while PRETR->DATA != NUM
Step 5: SET PREPTR = PTR
Step 6: SET PTR = PTR->NEXT
[END OF LOOP]
Step7: SET TEMP = PTR->NEXT
Step 8: SET PREPTR->NEXT = TEMP->NEXT
Step 9: FREE TEMP
Step 10: EXIT
1 7 3 4 2 6 5 X
START, PREPTR, PTR
1 7 3 4 2 6 5 X
PREPTR PTRSTART
1 7 3 4 2 6 5 X
START
1 7 3 4 6 5 X
START
© Oxford University Press 2011. All rights reserved.
Circular Linked List
• In a circular linked list, the last node contains a pointer to the
first node of the list. We can have a circular singly listed list as
well as circular doubly linked list. While traversing a circular
linked list, we can begin at any node and traverse the list in
any direction forward or backward until we reach the same
node where we had started. Thus, a circular linked list has no
beginning and no ending.
1 2 3 4 5 6 7
START
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node in the beginning of circular the linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 7
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET PTR = START
Step 6: Repeat Step 7 while PTR->NEXT != START
Step 7: PTR = PTR->NEXT
Step 8: SET New_Node->Next = START
Step 8: SET PTR->NEXT = New_Node
Step 6: SET START = New_Node
Step 7: EXIT
1 7 3 4 2 6 5
START, PTR
1 7 3 4 2 6 5
START
PTR
9 1 7 3 4 2 6 5
START
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node at the end of the circular linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 7
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = START
Step 6: SET PTR = START
Step 7: Repeat Step 8 while PTR->NEXT != START
Step 8: SET PTR = PTR ->NEXT
[END OF LOOP]
Step 9: SET PTR ->NEXT = New_Node
Step 10: EXIT
1 7 3 4 2 6 5
START, PTR
1 7 3 4 2 6 5 9
START PTR
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node after a node that has value NUM
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 12
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET PTR = START
Step 6: SET PREPTR = PTR
Step 7: Repeat Step 8 and 9 while PTR->DATA != NUM
Step 8: SET PREPTR = PTR
Step 9: SET PTR = PTR->NEXT
[END OF LOOP]
Step 10: PREPTR->NEXT = New_Node
Step 11: SET New_Node->NEXT = PTR
Step 12: EXIT
1 7 3 4 2 6 5
START, PTR, PREPTR
1 7 3 4 2 6 5
9
START PRE PTR PTR
1 7 3 9 4 2 6 5
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the first node from the circular linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 while PTR->NEXT != START
Step 4: SET PTR = PTR->NEXT
[END OF IF]
Step 5: SET PTR->NEXT = START->NEXT
Step 6: FREE START
Step 7: SET START = PTR->NEXT
Step 8: EXIT
1 7 3 4 2 6 5
START, PTR
1 7 3 4 2 6 5
START
PTR
7 3 4 2 6 5
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the last node of the circular linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 while PTR->NEXT != START
Step 4: SET PREPTR = PTR
Step 5: SET PTR = PTR->NEXT
[END OF LOOP]
Step 6: SET PREPTR->NEXT = START
Step 7: FREE PTR
Step 8: EXIT
1 7 3 4 2 6 5
START, PREPTR, PTR
1 7 3 4 2 6 5
START
PTR
PREPTR
1 7 3 4 2 6
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the node after a given node from the circular linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 9
[END OF IF]
Step 2: SET PTR = START
Step 3: SET PREPTR = PTR
Step 4: Repeat Step 5 and 6 while PREPTR->DATA != NUM
Step 5: SET PREPTR = PTR
Step 6: SET PTR = PTR->NEXT
[END OF LOOP]
Step 7: SET PREPTR->NEXT = PTR->NEXT
Step 8: FREE PTR
Step 9: EXIT
1 7 3 4 2 6 5
START, PREPTR, PTR
1 7 3 4 2 6 5
START PREPTR PTR
1 7 3 4 6 5
START
© Oxford University Press 2011. All rights reserved.
Doubly Linked List
A doubly linked list or a two way linked list is a more complex type
of linked list which contains a pointer to the next as well as
previous node in the sequence. Therefore, it consists of three parts
and not just two. The three parts are data, a pointer to the next
node and a pointer to the previous node
1X 1 2 3 4 X
START
In C language, the structure of a doubly linked list is given as,
struct node
{ struct node *prev;
int data;
struct node *next;
};
The prev field of the first node and the next field of the last node will
contain NULL. The prev field is used to store the address of the
preceding node. This would enable to traverse the list in the backward
direction as well.
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node in the beginning of the doubly linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 8
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->PREV = NULL
Step 6: SET New_Node->Next = START
Step 7: SET START = New_Node
Step 8: EXIT
1 7 3 4 2 XX
9 1 7 3 4X 2 X
START
START
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node at the end of the doubly linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 11
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = NULL
Step 6: SET PTR = START
Step 7: Repeat Step 8 while PTR->NEXT != NULL
Step 8: SET PTR = PTR->NEXT
[END OF LOOP]
Step 9: SET PTR->NEXT = New_Node
Step 10: New_Node->PREV = PTR
Step 11: EXIT
1 7 3 4 2 XX
START, PTR
1 7 3 4 2X 9 X
START
PTR
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node after a node that has value NUM
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 11
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET PTR = START
Step 6: Repeat Step 8 while PTR->DATA != NUM
Step 7: SET PTR = PTR->NEXT
[END OF LOOP]
Step 8: New_Node->NEXT = PTR->NEXT
Step 9: SET New_Node->PREV = PTR
Step 10: SET PTR->NEXT = New_Node
Step 11: EXIT
1 7 3 4 2 XX
START, PTR
1 7 3 4 2 XX
9
1 7 3 9 4X 2 X
START
START PTR
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the first node from the doubly linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 6
[END OF IF]
Step 2: SET PTR = START
Step 3: SET START = START->NEXT
Step 4: SET START->PREV = NULL
Step 5: FREE PTR
Step 6: EXIT
1 7 3 4 2 XX
START, PTR
7 3 4 2 X
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the last node of the doubly linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 7
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 and 5 while PTR->NEXT != NULL
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: SET PTR->PREV->NEXT = NULL
Step 6: FREE PTR
Step 7: EXIT
1 3 5 7 8X 9
1
X
START, PTR
1 3 5 7 8X 9
1
X
START PTR
1 3 5 7 8 XX
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the node after a given node from the doubly linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 9
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 while PTR->DATA != NUM
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: SET TEMP = PTR->NEXT
Step 6: SET PTR->NEXT = TEMP->NEXT
Step 7: SET TEMP->NEXT->PREV = PTR
Step 8: FREE TEMP
Step 9: EXIT
1 3 4 7 8X 9
1
X
1 3 4 7 8X 9
1
X
1 3 4 8 9 XX
START, PTR
START
PTR
START
© Oxford University Press 2011. All rights reserved.
Circular Doubly Linked List
• A circular doubly linked list or a circular two way linked list is a more complex
type of linked list which contains a pointer to the next as well as previous node in
the sequence.
• The difference between a doubly linked and a circular doubly linked list is same
as that exists between a singly linked list and a circular linked list. The circular
doubly linked list does not contain NULL in the previous field of the first node
and the next field of the last node. Rather, the next field of the last node stores
the address of the first node of the list, i.e; START. Similarly, the previous field
of the first field stores the address of the last node.
• Since a circular doubly linked list contains three parts in its structure, it calls for
more space per node and for more expensive basic operations. However, it
provides the ease to manipulate the elements of the list as it maintains pointers
to nodes in both the directions . The main advantage of using a circular doubly
linked list is that it makes searches twice as efficient.
1 1 2 3 4
START
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node in the beginning of the circular doubly
linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 12
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 6: SET START->PREV->NEXT = new_node;
Step 7: SET New_Node->PREV = START->PREV;
Step 8: SET START->PREV= new_Node;
Step 9: SET new_node->next = START;
Step 10: SET START = New_Node
Step 11: EXIT
1 7 3 4 2
START
9 1 7 3 4 2
START
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node at the end of the circular
doubly linked list
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 11
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET New_Node->Next = START
Step 6: SET New_Node->PREV = START->PREV
Step 7: EXIT
1 7 3 4 2
1 7 3 4 2 9
START
START
© Oxford University Press 2011. All rights reserved.
Algorithm to insert a new node after a node that has value NUM
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 11
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET New_Node->DATA = VAL
Step 5: SET PTR = START
Step 6: Repeat Step 8 while PTR->DATA != NUM
Step 7: SET PTR = PTR->NEXT
[END OF LOOP]
Step 8: New_Node->NEXT = PTR->NEXT
Step 9: SET PTR->NEXT->PREV = New_Node
Step 9: SET New_Node->PREV = PTR
Step 10: SET PTR->NEXT = New_Node
Step 11: EXIT
1 7 3 4 2
START, PTR
1 7 3 4 2
9START
PTR
1 7 3 9 4 2
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the first node from the circular doubly linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START
Step 3: SET PTR->PREV=>NEXT= PTR->NEXT
Step 4: SET PTR->NEXT->PREV = PTR->PREV
Step 5: SET START = START->NEXT
Step 6: FREE PTR
Step 7: EXIT
1 3 5 7 8 9
1
START, PTR
3 5 7 8 9
1
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the last node of the circular doubly linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 8
[END OF IF]
Step 2: SET PTR = START->PREV
Step 5: SET PTR->PREV->NEXT = START
Step 6: SET START->PREV = PTR->PREV
Step 7: FREE PTR
Step 8: EXIT
1 3 5 7 8 9
1
START PTR
1 3 5 7 8X
START
© Oxford University Press 2011. All rights reserved.
Algorithm to delete the node after a given node from the circular doubly
linked list
Step 1: IF START = NULL, then
Write UNDERFLOW
Go to Step 9
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 while PTR->DATA != NUM
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: SET TEMP = PTR->NEXT
Step 6: SET PTR->NEXT = TEMP->NEXT
Step 7: SET TEMP->NEXT->PREV = PTR
Step 8: FREE TEMP
Step 9: EXIT
1 3 5 7 8 9
1
START
1 3 5 7 8 9
1
START PTR
1 3 4 8 9
START
© Oxford University Press 2011. All rights reserved.
Header Linked List
• A header linked list is a special type of linked list which contains a header node
at the beginning of the list. So, in a header linked list START will not point to the
first node of the list but START will contain the address of the header node.
There are basically two variants of a header linked list-
• Grounded header linked list which stores NULL in the next field of the last node
• Circular header linked list which stores the address of the header node in the
next field of the last node. Here, the header node will denote the end of the list.
1 2 3 4 5 6 X
Header Node
START
1 2 3 4 5 6
Header Node
START
© Oxford University Press 2011. All rights reserved.
Algorithm to traverse a Circular Header Linked List
Step 1: SET PTR = START->NEXT
Step 2: Repeat Steps 3 and 4 while PTR != START
Step 3: Apply PROCESS to PTR->DATA
Step 4: SET PTR = PTR->NEXT
[END OF LOOP]
Step 5: EXIT
Algorithm to insert a new node after a given node
Step 1: IF AVAIL = NULL, then
Write OVERFLOW
Go to Step 10
[END OF IF]
Step 2: SET New_Node = AVAIL
Step 3: SET AVAIL = AVAIL->NEXT
Step 4: SET PTR = START->NEXT
Step 5: SET New_Node->DATA = VAL
Step 6: Repeat step 4 while PTR->DATA != NUM
Step 7: SET PTR = PTR->NEXT
[END OF LOOP]
Step 8: New_Node->NEXT = PTR->NEXT
Step 9: SET PTR->NEXT = New_Node
Step 10: EXIT

More Related Content

What's hot

358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10sumitbardhan
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structureeShikshak
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5sumitbardhan
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queuesBuxoo Abdullah
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Circular linked list
Circular linked list Circular linked list
Circular linked list sajinis3
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & DeletionAfaq Mansoor Khan
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsAfaq Mansoor Khan
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Balwant Gorad
 

What's hot (20)

358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10358 33 powerpoint-slides_10-trees_chapter-10
358 33 powerpoint-slides_10-trees_chapter-10
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5358 33 powerpoint-slides_5-arrays_chapter-5
358 33 powerpoint-slides_5-arrays_chapter-5
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Linked List
Linked ListLinked List
Linked List
 
Chapter 4 strings
Chapter 4 stringsChapter 4 strings
Chapter 4 strings
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Stack
StackStack
Stack
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Linked list
Linked listLinked list
Linked list
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 

Viewers also liked

Double linked list
Double linked listDouble linked list
Double linked listraviahuja11
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked listFahd Allebdi
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Lovelyn Rose
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)John C. Havens
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeAbhishek L.R
 
Open Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordOpen Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordHarry Surden
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017Carol Smith
 

Viewers also liked (18)

Double linked list
Double linked listDouble linked list
Double linked list
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil6. Linked list - Data Structures using C++ by Varsha Patil
6. Linked list - Data Structures using C++ by Varsha Patil
 
Linked list
Linked listLinked list
Linked list
 
linked list
linked list linked list
linked list
 
7 Myths of AI
7 Myths of AI7 Myths of AI
7 Myths of AI
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Linked list
Linked listLinked list
Linked list
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Doubly linked list
Doubly linked listDoubly linked list
Doubly linked list
 
Cyber Crime
Cyber CrimeCyber Crime
Cyber Crime
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Open Legal Data Workshop at Stanford
Open Legal Data Workshop at StanfordOpen Legal Data Workshop at Stanford
Open Legal Data Workshop at Stanford
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law OverviewHarry Surden - Artificial Intelligence and Law Overview
Harry Surden - Artificial Intelligence and Law Overview
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
 

Similar to 358 33 powerpoint-slides_8-linked-lists_chapter-8

Ch-17-Data Structures.ppt.pptx
Ch-17-Data Structures.ppt.pptxCh-17-Data Structures.ppt.pptx
Ch-17-Data Structures.ppt.pptxcoderasylem
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptssuser9dd05f
 
Introduction Linked Lists - Singly Linked List,
Introduction Linked Lists - Singly Linked List,Introduction Linked Lists - Singly Linked List,
Introduction Linked Lists - Singly Linked List,JayaKamal
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.pptAlliVinay1
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)Chandan Singh
 
cp264_lecture18_queue.ppt
cp264_lecture18_queue.pptcp264_lecture18_queue.ppt
cp264_lecture18_queue.pptssuserff72e4
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsAakash deep Singhal
 
Link list(by harshit)
Link list(by harshit)Link list(by harshit)
Link list(by harshit)Harshit Jain
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiSowmya Jyothi
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queueskalyanineve
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfAxmedcarb
 
10994103.ppt
10994103.ppt10994103.ppt
10994103.pptSushmaG48
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptxmsohail37
 

Similar to 358 33 powerpoint-slides_8-linked-lists_chapter-8 (20)

Ch-17-Data Structures.ppt.pptx
Ch-17-Data Structures.ppt.pptxCh-17-Data Structures.ppt.pptx
Ch-17-Data Structures.ppt.pptx
 
cp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.pptcp264_lecture13_14_linkedlist.ppt
cp264_lecture13_14_linkedlist.ppt
 
Introduction Linked Lists - Singly Linked List,
Introduction Linked Lists - Singly Linked List,Introduction Linked Lists - Singly Linked List,
Introduction Linked Lists - Singly Linked List,
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
unit 2- PPT.pdf
unit 2- PPT.pdfunit 2- PPT.pdf
unit 2- PPT.pdf
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
4.linked list(contd.)
4.linked list(contd.)4.linked list(contd.)
4.linked list(contd.)
 
DSModule2.pptx
DSModule2.pptxDSModule2.pptx
DSModule2.pptx
 
Stacks
StacksStacks
Stacks
 
cp264_lecture18_queue.ppt
cp264_lecture18_queue.pptcp264_lecture18_queue.ppt
cp264_lecture18_queue.ppt
 
Lecture 5 data structures and algorithms
Lecture 5 data structures and algorithmsLecture 5 data structures and algorithms
Lecture 5 data structures and algorithms
 
Linklist
LinklistLinklist
Linklist
 
Link list(by harshit)
Link list(by harshit)Link list(by harshit)
Link list(by harshit)
 
Bca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothiBca data structures linked list mrs.sowmya jyothi
Bca data structures linked list mrs.sowmya jyothi
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 
10994103.ppt
10994103.ppt10994103.ppt
10994103.ppt
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
 

More from sumitbardhan

358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15sumitbardhan
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14sumitbardhan
 
358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13sumitbardhan
 
358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12sumitbardhan
 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6sumitbardhan
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2sumitbardhan
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1sumitbardhan
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16sumitbardhan
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 

More from sumitbardhan (9)

358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15
 
358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14358 33 powerpoint-slides_14-sorting_chapter-14
358 33 powerpoint-slides_14-sorting_chapter-14
 
358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13358 33 powerpoint-slides_13-graphs_chapter-13
358 33 powerpoint-slides_13-graphs_chapter-13
 
358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12358 33 powerpoint-slides_12-heaps_chapter-12
358 33 powerpoint-slides_12-heaps_chapter-12
 
358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6358 33 powerpoint-slides_6-strings_chapter-6
358 33 powerpoint-slides_6-strings_chapter-6
 
358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2358 33 powerpoint-slides_2-functions_chapter-2
358 33 powerpoint-slides_2-functions_chapter-2
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16358 33 powerpoint-slides_16-files-their-organization_chapter-16
358 33 powerpoint-slides_16-files-their-organization_chapter-16
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 

Recently uploaded

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

358 33 powerpoint-slides_8-linked-lists_chapter-8

  • 1. © Oxford University Press 2011. All rights reserved. Data Structures Using CData Structures Using C Reema TharejaReema Thareja, Assistant Professor, Institute of Information Technology and Management, New Delhi
  • 2. © Oxford University Press 2011. All rights reserved. CHAPTER 8 LINKED LISTS
  • 3. © Oxford University Press 2011. All rights reserved. INTRODUCTION • A linked list in simple terms is a linear collection of data elements. These data elements are called nodes. • Linked list is a data structure which in turn can be used to implement other data structures. Thus, it acts as building block to implement data structures like stacks, queues and their variations. • A linked list can be perceived as a train or a sequence of nodes in which each node contain one or more data fields and a pointer to the next node. 1 2 3 4 5 6 7 X START In the above linked list, every node contains two parts- one integer and the other a pointer to the next node. The left part of the node which contains data may include a simple data type, an array or a structure. The right part of the node contains a pointer to the next node (or address of the next node in sequence). The last node will have no next node connected to it, so it will store a special value called NULL.
  • 4. © Oxford University Press 2011. All rights reserved. INTRODUCTION contd. • Linked list contains a pointer variable, START which stores the address of the first node in the list. • We can traverse the entire list using a single pointer variable START. The START node will contain the address of the first node; the next part of the first node will in turn store the address of its succeeding node. • Using this technique the individual nodes of the list will form a chain of nodes. If START = NULL, this means that the linked list is empty and contains no nodes. • In C, we will implement a linked list using the following code: • struct node • { • int data; • struct node *next; • };
  • 5. © Oxford University Press 2011. All rights reserved. 1 DATA NEXT H 4 E 7 L 8 L 10 O -1 1 2 3 4 5 6 7 8 9 10 START START pointing to the first element of the linked list in memory 9 AVAIL If we want to add a node to an already existing linked list in the memory, we will first find any free space in the memory and then use it to store the information. The operating system maintains a free pool which is a linked list of a of all free memory cells. It maintains a pointer variable AVAIL which stores the address of the first free space. When you delete a node from the linked list, the operating system adds the freed memory to the free pool. The operating system will perform this operation whenever it finds the CPU idle or whenever the programs are falling short of memory. The operating system scans through all the memory cells and mark the cells that are being used by some or the other program. Then, it collects all those cells which are not being used and add their address to the free pool so that it can be reused by the programs. This process is called garbage collection. The whole process of collecting unused memory cells (garbage collection) is transparent to the programmer.
  • 6. © Oxford University Press 2011. All rights reserved. Singly Linked List • A singly linked list is the simplest type of linked list in which every node contains some data and a pointer to the next node of the same data type. By saying that the node contains a pointer to the next node we mean that the node stores the address of the next node in sequence. 1 2 3 4 5 6 7 X START Algorithm for traversing a linked list Step 1: [INITIALIZE] SET PTR = START Step 2: Repeat Steps 3 and 4 while PTR != NULL Step 3: Apply Process to PTR->DATA Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: EXIT
  • 7. © Oxford University Press 2011. All rights reserved. Algorithm to print the information stored in each node of the linked list Step 1: [INITIALIZE] SET PTR = START Step 2: Repeat Steps 3 and 4 while PTR != NULL Step 3: Write PTR->DATA Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: EXIT Algorithm to print the number of nodes in the linked list Step 1: [INITIALIZE] SET Count = 0 Step 2: [INITIALIZE] SET PTR = START Step 3: Repeat Steps 4 and 5 while PTR != NULL Step 4: SET Count = Count + 1 Step 5: SET PTR = PTR->NEXT [END OF LOOP] Step 6: EXIT
  • 8. © Oxford University Press 2011. All rights reserved. Algorithm to search an unsorted linked list Step 1: [INITIALIZE] SET PTR = START Step 2: Repeat Steps 3 while PTR != NULL Step 3: IF VAL = PTR->DATA SET POS = PTR Go To Step 5 ELSE SET PTR = PTR->NEXT [END OF IF] [END OF LOOP] Step 4: SET POS = NULL Step 5: EXIT 1 7 3 4 2 6 5 X PTR 1 7 3 4 2 6 5 X PTR 1 7 3 4 2 6 5 X PTR 1 7 3 4 2 6 5 X PTR
  • 9. © Oxford University Press 2011. All rights reserved. 1 7 3 4 2 6 5 X START START Algorithm to insert a new node in the beginning of the linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 7 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = START Step 6: SET START = New_Node Step 7: EXIT 9 1 7 3 4 2 6 5 X
  • 10. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node at the end of the linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 10 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = NULL Step 6: SET PTR = START Step 7: Repeat Step 8 while PTR->NEXT != NULL Step 8: SET PTR = PTR ->NEXT [END OF LOOP] Step 9: SET PTR->NEXT = New_Node Step 10: EXIT 1 7 3 4 2 6 5 X START, PTR 1 7 3 4 2 6 5 9 X PTRSTART
  • 11. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node after a node that has value NUM Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 12 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET PTR = START Step 6: SET PREPTR = PTR Step 7: Repeat Step 8 and 9 while PREPTR->DATA != NUM Step 8: SET PREPTR = PTR Step 9: SET PTR = PTR->NEXT [END OF LOOP] Step 10: PREPTR->NEXT = New_Node Step 11: SET New_Node->NEXT = PTR Step 12: EXIT 51 7 3 4 2 6 X START, PTR, PREPTR 1 7 3 4 2 6 5 X START PREPTR PTR 1 7 3 9 4 2 6 5 X START
  • 12. © Oxford University Press 2011. All rights reserved. Algorithm to delete the first node from the linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 5 [END OF IF] Step 2: SET PTR = START Step 3: SET START = START->NEXT Step 4: FREE PTR Step 5: EXIT 1 7 3 4 2 6 5 X 7 3 4 2 6 5 X START START
  • 13. © Oxford University Press 2011. All rights reserved. Algorithm to delete the last node of the linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 8 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 and 5 while PTR->NEXT != NULL Step 4: SET PREPTR = PTR Step 5: SET PTR = PTR->NEXT [END OF LOOP] Step 6: SET PREPTR->NEXT = NULL Step 7: FREE PTR Step 8: EXIT 1 7 3 4 2 6 5 X START, PREPTR, PTR 1 7 3 4 2 6 X 5 X PREPTR PTRSTART
  • 14. © Oxford University Press 2011. All rights reserved. Algorithm to delete the node after a given node from the linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 10 [END OF IF] Step 2: SET PTR = START Step 3: SET PREPTR = PTR Step 4: Repeat Step 5 and 6 while PRETR->DATA != NUM Step 5: SET PREPTR = PTR Step 6: SET PTR = PTR->NEXT [END OF LOOP] Step7: SET TEMP = PTR->NEXT Step 8: SET PREPTR->NEXT = TEMP->NEXT Step 9: FREE TEMP Step 10: EXIT 1 7 3 4 2 6 5 X START, PREPTR, PTR 1 7 3 4 2 6 5 X PREPTR PTRSTART 1 7 3 4 2 6 5 X START 1 7 3 4 6 5 X START
  • 15. © Oxford University Press 2011. All rights reserved. Circular Linked List • In a circular linked list, the last node contains a pointer to the first node of the list. We can have a circular singly listed list as well as circular doubly linked list. While traversing a circular linked list, we can begin at any node and traverse the list in any direction forward or backward until we reach the same node where we had started. Thus, a circular linked list has no beginning and no ending. 1 2 3 4 5 6 7 START
  • 16. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node in the beginning of circular the linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 7 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET PTR = START Step 6: Repeat Step 7 while PTR->NEXT != START Step 7: PTR = PTR->NEXT Step 8: SET New_Node->Next = START Step 8: SET PTR->NEXT = New_Node Step 6: SET START = New_Node Step 7: EXIT 1 7 3 4 2 6 5 START, PTR 1 7 3 4 2 6 5 START PTR 9 1 7 3 4 2 6 5 START
  • 17. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node at the end of the circular linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 7 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = START Step 6: SET PTR = START Step 7: Repeat Step 8 while PTR->NEXT != START Step 8: SET PTR = PTR ->NEXT [END OF LOOP] Step 9: SET PTR ->NEXT = New_Node Step 10: EXIT 1 7 3 4 2 6 5 START, PTR 1 7 3 4 2 6 5 9 START PTR
  • 18. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node after a node that has value NUM Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 12 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET PTR = START Step 6: SET PREPTR = PTR Step 7: Repeat Step 8 and 9 while PTR->DATA != NUM Step 8: SET PREPTR = PTR Step 9: SET PTR = PTR->NEXT [END OF LOOP] Step 10: PREPTR->NEXT = New_Node Step 11: SET New_Node->NEXT = PTR Step 12: EXIT 1 7 3 4 2 6 5 START, PTR, PREPTR 1 7 3 4 2 6 5 9 START PRE PTR PTR 1 7 3 9 4 2 6 5
  • 19. © Oxford University Press 2011. All rights reserved. Algorithm to delete the first node from the circular linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 8 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 while PTR->NEXT != START Step 4: SET PTR = PTR->NEXT [END OF IF] Step 5: SET PTR->NEXT = START->NEXT Step 6: FREE START Step 7: SET START = PTR->NEXT Step 8: EXIT 1 7 3 4 2 6 5 START, PTR 1 7 3 4 2 6 5 START PTR 7 3 4 2 6 5 START
  • 20. © Oxford University Press 2011. All rights reserved. Algorithm to delete the last node of the circular linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 8 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 while PTR->NEXT != START Step 4: SET PREPTR = PTR Step 5: SET PTR = PTR->NEXT [END OF LOOP] Step 6: SET PREPTR->NEXT = START Step 7: FREE PTR Step 8: EXIT 1 7 3 4 2 6 5 START, PREPTR, PTR 1 7 3 4 2 6 5 START PTR PREPTR 1 7 3 4 2 6 START
  • 21. © Oxford University Press 2011. All rights reserved. Algorithm to delete the node after a given node from the circular linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 9 [END OF IF] Step 2: SET PTR = START Step 3: SET PREPTR = PTR Step 4: Repeat Step 5 and 6 while PREPTR->DATA != NUM Step 5: SET PREPTR = PTR Step 6: SET PTR = PTR->NEXT [END OF LOOP] Step 7: SET PREPTR->NEXT = PTR->NEXT Step 8: FREE PTR Step 9: EXIT 1 7 3 4 2 6 5 START, PREPTR, PTR 1 7 3 4 2 6 5 START PREPTR PTR 1 7 3 4 6 5 START
  • 22. © Oxford University Press 2011. All rights reserved. Doubly Linked List A doubly linked list or a two way linked list is a more complex type of linked list which contains a pointer to the next as well as previous node in the sequence. Therefore, it consists of three parts and not just two. The three parts are data, a pointer to the next node and a pointer to the previous node 1X 1 2 3 4 X START In C language, the structure of a doubly linked list is given as, struct node { struct node *prev; int data; struct node *next; }; The prev field of the first node and the next field of the last node will contain NULL. The prev field is used to store the address of the preceding node. This would enable to traverse the list in the backward direction as well.
  • 23. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node in the beginning of the doubly linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 8 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->PREV = NULL Step 6: SET New_Node->Next = START Step 7: SET START = New_Node Step 8: EXIT 1 7 3 4 2 XX 9 1 7 3 4X 2 X START START
  • 24. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node at the end of the doubly linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 11 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = NULL Step 6: SET PTR = START Step 7: Repeat Step 8 while PTR->NEXT != NULL Step 8: SET PTR = PTR->NEXT [END OF LOOP] Step 9: SET PTR->NEXT = New_Node Step 10: New_Node->PREV = PTR Step 11: EXIT 1 7 3 4 2 XX START, PTR 1 7 3 4 2X 9 X START PTR
  • 25. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node after a node that has value NUM Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 11 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET PTR = START Step 6: Repeat Step 8 while PTR->DATA != NUM Step 7: SET PTR = PTR->NEXT [END OF LOOP] Step 8: New_Node->NEXT = PTR->NEXT Step 9: SET New_Node->PREV = PTR Step 10: SET PTR->NEXT = New_Node Step 11: EXIT 1 7 3 4 2 XX START, PTR 1 7 3 4 2 XX 9 1 7 3 9 4X 2 X START START PTR
  • 26. © Oxford University Press 2011. All rights reserved. Algorithm to delete the first node from the doubly linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 6 [END OF IF] Step 2: SET PTR = START Step 3: SET START = START->NEXT Step 4: SET START->PREV = NULL Step 5: FREE PTR Step 6: EXIT 1 7 3 4 2 XX START, PTR 7 3 4 2 X
  • 27. © Oxford University Press 2011. All rights reserved. Algorithm to delete the last node of the doubly linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 7 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 and 5 while PTR->NEXT != NULL Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: SET PTR->PREV->NEXT = NULL Step 6: FREE PTR Step 7: EXIT 1 3 5 7 8X 9 1 X START, PTR 1 3 5 7 8X 9 1 X START PTR 1 3 5 7 8 XX START
  • 28. © Oxford University Press 2011. All rights reserved. Algorithm to delete the node after a given node from the doubly linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 9 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 while PTR->DATA != NUM Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: SET TEMP = PTR->NEXT Step 6: SET PTR->NEXT = TEMP->NEXT Step 7: SET TEMP->NEXT->PREV = PTR Step 8: FREE TEMP Step 9: EXIT 1 3 4 7 8X 9 1 X 1 3 4 7 8X 9 1 X 1 3 4 8 9 XX START, PTR START PTR START
  • 29. © Oxford University Press 2011. All rights reserved. Circular Doubly Linked List • A circular doubly linked list or a circular two way linked list is a more complex type of linked list which contains a pointer to the next as well as previous node in the sequence. • The difference between a doubly linked and a circular doubly linked list is same as that exists between a singly linked list and a circular linked list. The circular doubly linked list does not contain NULL in the previous field of the first node and the next field of the last node. Rather, the next field of the last node stores the address of the first node of the list, i.e; START. Similarly, the previous field of the first field stores the address of the last node. • Since a circular doubly linked list contains three parts in its structure, it calls for more space per node and for more expensive basic operations. However, it provides the ease to manipulate the elements of the list as it maintains pointers to nodes in both the directions . The main advantage of using a circular doubly linked list is that it makes searches twice as efficient. 1 1 2 3 4 START
  • 30. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node in the beginning of the circular doubly linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 12 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 6: SET START->PREV->NEXT = new_node; Step 7: SET New_Node->PREV = START->PREV; Step 8: SET START->PREV= new_Node; Step 9: SET new_node->next = START; Step 10: SET START = New_Node Step 11: EXIT 1 7 3 4 2 START 9 1 7 3 4 2 START
  • 31. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node at the end of the circular doubly linked list Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 11 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET New_Node->Next = START Step 6: SET New_Node->PREV = START->PREV Step 7: EXIT 1 7 3 4 2 1 7 3 4 2 9 START START
  • 32. © Oxford University Press 2011. All rights reserved. Algorithm to insert a new node after a node that has value NUM Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 11 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET New_Node->DATA = VAL Step 5: SET PTR = START Step 6: Repeat Step 8 while PTR->DATA != NUM Step 7: SET PTR = PTR->NEXT [END OF LOOP] Step 8: New_Node->NEXT = PTR->NEXT Step 9: SET PTR->NEXT->PREV = New_Node Step 9: SET New_Node->PREV = PTR Step 10: SET PTR->NEXT = New_Node Step 11: EXIT 1 7 3 4 2 START, PTR 1 7 3 4 2 9START PTR 1 7 3 9 4 2 START
  • 33. © Oxford University Press 2011. All rights reserved. Algorithm to delete the first node from the circular doubly linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 8 [END OF IF] Step 2: SET PTR = START Step 3: SET PTR->PREV=>NEXT= PTR->NEXT Step 4: SET PTR->NEXT->PREV = PTR->PREV Step 5: SET START = START->NEXT Step 6: FREE PTR Step 7: EXIT 1 3 5 7 8 9 1 START, PTR 3 5 7 8 9 1 START
  • 34. © Oxford University Press 2011. All rights reserved. Algorithm to delete the last node of the circular doubly linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 8 [END OF IF] Step 2: SET PTR = START->PREV Step 5: SET PTR->PREV->NEXT = START Step 6: SET START->PREV = PTR->PREV Step 7: FREE PTR Step 8: EXIT 1 3 5 7 8 9 1 START PTR 1 3 5 7 8X START
  • 35. © Oxford University Press 2011. All rights reserved. Algorithm to delete the node after a given node from the circular doubly linked list Step 1: IF START = NULL, then Write UNDERFLOW Go to Step 9 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 while PTR->DATA != NUM Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: SET TEMP = PTR->NEXT Step 6: SET PTR->NEXT = TEMP->NEXT Step 7: SET TEMP->NEXT->PREV = PTR Step 8: FREE TEMP Step 9: EXIT 1 3 5 7 8 9 1 START 1 3 5 7 8 9 1 START PTR 1 3 4 8 9 START
  • 36. © Oxford University Press 2011. All rights reserved. Header Linked List • A header linked list is a special type of linked list which contains a header node at the beginning of the list. So, in a header linked list START will not point to the first node of the list but START will contain the address of the header node. There are basically two variants of a header linked list- • Grounded header linked list which stores NULL in the next field of the last node • Circular header linked list which stores the address of the header node in the next field of the last node. Here, the header node will denote the end of the list. 1 2 3 4 5 6 X Header Node START 1 2 3 4 5 6 Header Node START
  • 37. © Oxford University Press 2011. All rights reserved. Algorithm to traverse a Circular Header Linked List Step 1: SET PTR = START->NEXT Step 2: Repeat Steps 3 and 4 while PTR != START Step 3: Apply PROCESS to PTR->DATA Step 4: SET PTR = PTR->NEXT [END OF LOOP] Step 5: EXIT Algorithm to insert a new node after a given node Step 1: IF AVAIL = NULL, then Write OVERFLOW Go to Step 10 [END OF IF] Step 2: SET New_Node = AVAIL Step 3: SET AVAIL = AVAIL->NEXT Step 4: SET PTR = START->NEXT Step 5: SET New_Node->DATA = VAL Step 6: Repeat step 4 while PTR->DATA != NUM Step 7: SET PTR = PTR->NEXT [END OF LOOP] Step 8: New_Node->NEXT = PTR->NEXT Step 9: SET PTR->NEXT = New_Node Step 10: EXIT