Lecture - 6 �On�Data Structures
Linked list
Lecture Outline
Inserting into a sorted linked list
SAVE : =PTR and PTR : =LINK[PTR]
START
Node A
Node B
Fig :5-20
SAVE
PTR
Finding a Node
FINDA(INFO, LINK, START, ITEM, LOC)
This procedure finds the location LOC of the last node in a sorted list such that
INFO[LOC] < ITEM or sets LOC= NULL
Set LOC = NULL and return.
Set LOC = NULL and return.
Set LOC= SAVE and Return.
(End of step 4)
Inserting into a sorted linked list
Algorithm 5.7: INSSRT(INFO, LINK, START, AVAIL, ITEM)
This algorithm inserts an item into a sorted linked list.
Deletion from a Linked List
START
Node A
Node N
(a) Before deletion
Node B
Node A
Node B
After deletion
AVAIL
Free storage list
START
Node N
Deleting a node
Finding a Node
FINDB(INFO, LINK, START, ITEM, LOC, LOCP)
This procedure finds the location LOC of the first node N which contains ITEM and the location LOCP of the node preceding node N.
Set LOC = NULL and LOCP = NULL and return.
Set LOC = START and LOCP = NULL and return.
Set LOC= PTR and LOCP = SAVE and Return.
Deleting a node
DELETE(INFO, LINK, START, AVAIL, ITEM)
IF LOCP = NULL then:
Set START= = LINK[START] [Delete first node]
Else:
Set LINK[LOCP] = LINK [LOC]
Set LINK[LOC] = AVAIL and AVAIL = LOC
Deleting a node
LOC
START
DELETE(INFO, LINK, START, AVAIL, ITEM)
IF LOCP = NULL then:
Set START= = LINK[START] [Delete first node]
Else:
Set LINK[LOCP] = LINK [LOC]
Set LINK[LOC] = AVAIL and AVAIL = LOC
Deleting a node
LOC
LOCP
DELETE(INFO, LINK, START, AVAIL, ITEM)
IF LOCP = NULL then:
Set START= = LINK[START] [Delete first node]
Else:
Set LINK[LOCP] = LINK [LOC]
Set LINK[LOC] = AVAIL and AVAIL = LOC
Variations of Linked Lists
Variations of Linked Lists�
circular linked list:
CIRCULAR LIST with header node
CIRCULAR LIST with header node
Example of application of circular linked list
Advantages
Linear linked list vs Circular Linked Lists
Variations of Linked Lists
A
Head
B
∅
C
∅
The primary disadvantage of doubly linked lists are that
Each node points to not only successor but the predecessor
There are two NULL: at the first and last nodes in the list
Example :Doubly linked lists�
Array versus Linked Lists