SlideShare a Scribd company logo
1 of 56
Introduction: memory representation, allocation
and garbage collection.
Operations: Traversal, insertion and deletion.
Header linked lists: Grounded and Circular
Two-way lists: operations on two way linked lists
Introduction
 Linked list
 Linear collection of self-referential class objects, called
nodes
 Connected by pointer links
 Accessed via a pointer to the first node of the list
 Link pointer in the last node is set to null to mark the list’s
end
 Use a linked list instead of an array when
 You have an unpredictable number of data elements
 You want to insert and delete quickly.
Self-Referential Structures
 Self-referential structures
 Structure that contains a pointer to a structure of the same type
 Can be linked together to form useful data structures such as lists, queues,
stacks and trees
 Terminated with a NULL pointer (0)
 Diagram of two self-referential structure objects linked together
struct node {
int data;
struct node *nextPtr;
};
 nextPtr
 Points to an object of type node
 Referred to as a link
100
NULL pointer (points to nothing)
Data member and pointer
500
…
3 2
Linked Lists
 Types of linked lists:
 Singly linked list
 Begins with a pointer to the first node
 Terminates with a null pointer
 Only traversed in one direction
 Circular, singly linked
 Pointer in the last node points
back to the first node
 Doubly linked list
 Two “start pointers” – first element and last element
 Each node has a forward pointer and a backward pointer
 Allows traversals both forwards and backwards
 Circular, doubly linked list
 Forward pointer of the last node points to the first node and
backward pointer of the first node points to the last node
Linked Representation of Data
 In a linked representation, data is
not stored in a contiguous manner.
Instead, data is stored at random
locations and the current data
location provides the information
regarding the location of the next
data.
Adding item 498 on to the linked list
Q: What is the cost of adding an item?
Q: how about adding 300 and 800
onto the linked list
Deleting item 358 from the linked list
Q: What is the cost of deleting an item?
Q: What is the cost of searching for an
item?
345
358
490
501
513
724
797
701
561
555
345
358
490
501
513
724
797
701
561
555
498
345
358
490
501
513
724
797
701
561
555
498
Linked List
 How do we represent a linked list in the memory
 Each location has two fields: Data Field and Pointer (Link)
Field.
 Linked List Implementation
 struct node {
int data;
struct node *link;
};
struct node my_node;
Example:
START Node
Element
Pointer (Link)
Field
Data
Field
Null Pointer
300 5
500 0
100 4
200 1
400 2
1
2
3
4
5
3
NULL
Conventions of Linked List
There are several conventions for the link to indicate the
end of the list.
1. a null link that points to no node (0 or NULL)
2. a dummy node that contains no item
3. a reference back to the first node, making it a
circular list.
bat  cat  sat  vat NULL
Singly Linked List
Linked List Manipulation Algorithms
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
Linked-List Traversal
PTR
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: Write COUNT
Step 7: EXIT
Print the nos. of nodes in a Linked List
Step 1: [INITIALIZE] SET PTR = START
Step 2: Repeat Step 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
Search for an ITEM in a Linked List
Search for an ITEM in a Linked List
Insert an Item
Inserting a Node at the Beginning of a Linked List
Step 1: IF AVAIL = NULL
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
Insert an Item
Inserting a Node at the Beginning of a Linked List
Insert an Item
Inserting a Node at the End of a Linked List
Step 1: IF AVAIL = NULL
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
Insert an Item
Inserting a Node at the End of a Linked List
Inserting a Node After a Given Node in a Linked List
// using search algo
Step 1: IF AVAIL = NULL
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 PTR = START
Step 6: Repeat Step 3 while PTR != NULL
Step 7: IF VAL = PTR->DATA
SET POS = PTR
SET NEW_NODE->NEXT = PTRNEXT
PTR->NEXT = NEW_NODE and Exit
ELSE
SET PTR = PTR->NEXT
[END OF IF]
[END OF LOOP]
Step 8: If POS = NULL then Write “Item not found”
Step 9: Exit
Insert an Item
Inserting a Node After a Given Node in a Linked List
Insert an Item
Inserting a Node Before a Given Node in a Linked List
Step 1: IF AVAIL = NULL
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: if PTR->DATA = NUM
SET NEW_NODE-> NEXT = START
SET START = NEW_NODE and EXIT
Step 7:Repeat while PTR->DATA != NUM
SET PREPTR = PTR
SET PTR = PTR->NEXT
[END OF LOOP]
Step 8: SET NEW_NODE->NEXT = PREPTRNEXT
Step 9: PREPTR->NEXT = NEW_NODE
Step 10: EXIT
Delete an Item
Deleting the First Node from a Linked List
Step 1: IF START = NULL
Write UNDERFLOW
Go to Step 5
[END OF IF]
Step 2: SET PTR = START
Step 3: SET START = START->NEXT
Step 4: FREE PTR or SET PTR -> NEXT = AVAIL and AVAIL = PTR
Step 5: EXIT
Delete an Item
Deleting the Last Node from a Linked List
1.IF START=NULL Print Underflow and Exit
2.Set PTR=START and PREPTR=START
3.Repeat 4 While PTR->LINK!=NULL
4.1.Set PREPTR=PTR
4.2.Set PTR=PTR->LINK
5.If PTR==START Set START=NULL
6.Else PREPTR->LINK=NULL
7.PTR->LINK=AVAIL and AVAIL=PTR
8.EXIT
Delete an Item
Deleting the Last Node from a Linked List
Delete an Item
Deleting the Node After a Given Node in a Linked List
1: IF START = NULL
Write UNDERFLOW
go to step 8
2: set PTR = START
3: while PTR->DATA !=KEY
SET PTR= PTR->NEXT
end of loop
4.TEMP=PTR->NEXT
5: SET PTR->NEXT =(PTR->NEXT)->NEXT
6:SET TEMP -> NEXT = AVAIL
7:.AVAIL=TEMP
8: EXIT
Delete an Item
Deleting the Node After a Given Node in a Linked List
Deleting the node after a Given
Node in a Linked List
Step 1: IF START = NULL
Write UNDERFLOW
Go to Step 10
[END OF IF]
Step 2: SET PTR = START
Step 3: SET PREPTR = PTR
Step 4: Repeat Steps 5 and 6 while PREPTR->DATA != NUM
Step 5: SET PREPTR = PTR
Step 6: SET PTR = PTR->NEXT
[END OF LOOP]
Step 7: SET TEMP = PTR
Step 8: SET PREPTR->NEXT = PTR->NEXT
Step 9: FREE TEMP or SET TEMP -> LINK = AVAIL and AVAIL =
TEMP
Step 10: EXIT
Delete the given node
step1: if start =NULL
Write: Underflow and exit
Step 2: SET ptr=start;
Step3:
if start->info == key
SET start=start->link goto step 6
Step4: repeat while ptr!=NULL && ptr->info!=key
4.1 SET pptr=ptr;
4.2 SET ptr=ptr->link;
Step5: SET pptr->link=ptr->link;
Step6: SET PTR -> LINK = AVAIL and AVAIL = PTR
Step 7: EXIT
Circular Linked List
Circular Linked-List Traversal
Step 1: [INITIALIZE] SET PTR = START
Step 2: Apply Process to PTR->DATA
Step 3: PTR = PTR->NEXT
Step 4: Repeat Steps 5 and 6 while PTR != START
Step 5: Apply Process to PTR->DATA
Step 6: SET PTR = PTR->NEXT
[END OF LOOP]
Step 7: EXIT
Circular Linked List
Inserting a Node at the Beginning of a Circular Linked List
Inserting a Node at the Beginning of a Circular Linked List
Inserting a Node at the End of a Circular Linked List
Inserting a Node at the End of a Circular Linked List
Deleting the First Node from a Circular Linked List
Deleting the First Node from a Circular Linked List
Deleting the Last Node from a Circular Linked List
Deleting the Last Node from a Circular Linked List
Header Linked Lists
 Header linked list is a linked list which always contains a
special node called the Header Node, at the beginning of
the list.
 It has two types:
a) Grounded Header List
Last Node Contains the NULL Pointer
b) Circular Header List
Last Node Points Back to the Header Node
36
Header linked list
Grounded Header linked list Circular Header linked list
Grounded Header Link List
 A grounded header list is a header list where the last
node contains the null pointer.
 The term “grounded” comes from the fact that many
texts use the electrical ground symbol to indicate the
null pointer.
Header Node
Start
Figure: Grounded Header Link List
Circular Header Linked List
 A circular header Link list is a header list where the last
node points back to the header node.
 The chains do not indicate the last node and first node of
the link list.
 In this case, external pointers provide a frame reference
because last node of a circular link list does not contain
null pointer.
Header Node
Figure: Circular Header Link List
Start
Benefit of using Header Node
 One way to simplify insertion and deletion is never to
insert an item before the first or after the last item and
never to delete the first node
 You can set a header node at the beginning of the list
containing a value smaller than the smallest value in the
data set
 You can set a trailer node at the end of the list containing a
value larger than the largest value in the data set.
 These two nodes, header and trailer, serve merely to
simplify the insertion and deletion algorithms and are not
part of the actual list.
 The actual list is between these two nodes.
Two-way lists
 A two-way list is a linear collection of data elements,
called nodes, where each node N is divided into three
parts:
 Information field
 Forward Link which points to the next node
 Backward Link which points to the previous node
 The starting address or the address of first node is
stored in START / FIRST pointer .
 Another pointer can be used to traverse list from end.
This pointer is called END or LAST.
Two-way lists(cont…)
 Every node (except the last node) contains the
address of the next node, and every node (except
the first node) contains the address of the previous
node.
 A two-way list (doubly linked list) can be traversed
in either direction.
Representations of
Two-way lists
Start
X 4 2 10
Last
Data Field
Prev Pointer
Next Pointer
X
Traversing a doubly-LL
 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
Traversing from end.
 Step 1: [INITIALIZE] SET PTR = END
 Step 2: Repeat Steps 3 and 4 while PTR !=
NULL
 Step 3: Apply Process to PTR->DATA
 Step 4: SET PTR = PTR->Prev
 [END OF LOOP]
 Step 5: EXIT
Insert an Item
Inserting a Node at the Beginning of a Doubly Linked List
Step 1: IF AVAIL = NULL
Write OVERFLOW
Go to Step 9
[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 -> PREV = NEW_NODE
Step 8: SET START = NEW_NODE
Step 9: EXIT
Inserting a Node at the End of a Doubly Linked List
Step 1: IF AVAIL = NULL
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: SET NEW_NODE -> PREV = PTR
Step 11: EXIT
Step 1: IF AVAIL = NULL
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: Repeat Step 7 while PTR -> DATA != NUM
Step 7: SET PTR = PTR -> NEXT
[END OF LOOP]
Step 8: SET NEW_NODE -> NEXT = PTR -> NEXT
Step 9: SET NEW_NODE -> PREV = PTR
Step 10: SET PTR -> NEXT -> PREV = NEW_NODE
Step 11: SET PTR -> NEXT = NEW_NODE
Step 12: EXIT
Inserting a Node After a Given Node in a Doubly Linked List
Inserting a Node After a Given Node in a Doubly Linked List
Step 1: IF AVAIL = NULL
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: Repeat Step 7 while PTR -> DATA != NUM
Step 7: SET PTR = PTR -> NEXT
[END OF LOOP]
Step 8: SET NEW_NODE -> PREV=PTR->PREV
Step 9: SET NEW_NODE -> NEXT= PTR
Step 9: SET PTR-> PREV -> NEXT = NEW_NODE
Step 10: SET PTR -> PREV = NEWNODE
Step 12: EXIT
Inserting a Node Before a Given Node in a Doubly Linked List
Step 1: IF START = NULL
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
Delete an Item
Deleting the First Node from a Doubly Linked List
Delete an Item
Deleting the Last Node from a Doubly Linked List
Step 1: IF START = NULL
Write UNDERFLOW
Go to Step 7
[END OF IF]
Step 2: SET PTR = START
Step 3: Repeat Step 4 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
Delete an Item
Deleting the Node After a Given Node from a Doubly Linked List
Step 1: IF START = NULL
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
Deletion in 2-way Doubly LL
 DELTWL(INFO,FORW,BACK,START,AVAIL,LOC)
 1.SET FORW[BACK[LOC]]=FORW[LOC]
 BACK[FORW[LOC]]=BACK[LOC]
 2. SET FORW[LOC]=AVAIL and AVAIL=LOC
 3.Exit
Insertion in 2-way Doubly LL
 INSTTWL(INFO,FORW,BACK,START,AVAIL,LOCA,L
OCB,ITEM)
 1. IF AVAIL=NULL Set OVERFLOW and Exit
 2. SET NEW=AVAIL and AVAIL=FORW[AVAIL],
INFO[NEW]=ITEM
 3.SET FORW[LOCA]=NEW,FORW[NEW]=LOCB,
 BACK[LOCB]=NEW, BACK[NEW]=LOCA
 4.Exit
Thank You

More Related Content

Similar to Linked List Data Structures: Operations, Types and Implementations

Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queueskalyanineve
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptxmsohail37
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked ListThenmozhiK5
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of listsmuskans14
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notesDreamers6
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8sumitbardhan
 

Similar to Linked List Data Structures: Operations, Types and Implementations (20)

Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Singly link list
Singly link listSingly link list
Singly link list
 
Linked Lists.pdf
Linked Lists.pdfLinked Lists.pdf
Linked Lists.pdf
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linked List.pptx
Linked List.pptxLinked List.pptx
Linked List.pptx
 
DS_LinkedList.pptx
DS_LinkedList.pptxDS_LinkedList.pptx
DS_LinkedList.pptx
 
Linklist
LinklistLinklist
Linklist
 
DS Unit 2.ppt
DS Unit 2.pptDS Unit 2.ppt
DS Unit 2.ppt
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Linked list
Linked listLinked list
Linked list
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 
Linked list
Linked list Linked list
Linked list
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 
Linked List
Linked ListLinked List
Linked List
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
data structures lists operation of lists
data structures lists operation of listsdata structures lists operation of lists
data structures lists operation of lists
 
Module 3 Dara structure notes
Module 3 Dara structure notesModule 3 Dara structure notes
Module 3 Dara structure notes
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 

Recently uploaded

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...Call girls in Ahmedabad High profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 

Linked List Data Structures: Operations, Types and Implementations

  • 1. Introduction: memory representation, allocation and garbage collection. Operations: Traversal, insertion and deletion. Header linked lists: Grounded and Circular Two-way lists: operations on two way linked lists
  • 2. Introduction  Linked list  Linear collection of self-referential class objects, called nodes  Connected by pointer links  Accessed via a pointer to the first node of the list  Link pointer in the last node is set to null to mark the list’s end  Use a linked list instead of an array when  You have an unpredictable number of data elements  You want to insert and delete quickly.
  • 3. Self-Referential Structures  Self-referential structures  Structure that contains a pointer to a structure of the same type  Can be linked together to form useful data structures such as lists, queues, stacks and trees  Terminated with a NULL pointer (0)  Diagram of two self-referential structure objects linked together struct node { int data; struct node *nextPtr; };  nextPtr  Points to an object of type node  Referred to as a link 100 NULL pointer (points to nothing) Data member and pointer 500 … 3 2
  • 4. Linked Lists  Types of linked lists:  Singly linked list  Begins with a pointer to the first node  Terminates with a null pointer  Only traversed in one direction  Circular, singly linked  Pointer in the last node points back to the first node  Doubly linked list  Two “start pointers” – first element and last element  Each node has a forward pointer and a backward pointer  Allows traversals both forwards and backwards  Circular, doubly linked list  Forward pointer of the last node points to the first node and backward pointer of the first node points to the last node
  • 5. Linked Representation of Data  In a linked representation, data is not stored in a contiguous manner. Instead, data is stored at random locations and the current data location provides the information regarding the location of the next data. Adding item 498 on to the linked list Q: What is the cost of adding an item? Q: how about adding 300 and 800 onto the linked list Deleting item 358 from the linked list Q: What is the cost of deleting an item? Q: What is the cost of searching for an item? 345 358 490 501 513 724 797 701 561 555 345 358 490 501 513 724 797 701 561 555 498 345 358 490 501 513 724 797 701 561 555 498
  • 6. Linked List  How do we represent a linked list in the memory  Each location has two fields: Data Field and Pointer (Link) Field.  Linked List Implementation  struct node { int data; struct node *link; }; struct node my_node; Example: START Node Element Pointer (Link) Field Data Field Null Pointer 300 5 500 0 100 4 200 1 400 2 1 2 3 4 5 3 NULL
  • 7. Conventions of Linked List There are several conventions for the link to indicate the end of the list. 1. a null link that points to no node (0 or NULL) 2. a dummy node that contains no item 3. a reference back to the first node, making it a circular list.
  • 8. bat  cat  sat  vat NULL Singly Linked List
  • 9. Linked List Manipulation Algorithms 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 Linked-List Traversal PTR
  • 10. 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: Write COUNT Step 7: EXIT Print the nos. of nodes in a Linked List
  • 11. Step 1: [INITIALIZE] SET PTR = START Step 2: Repeat Step 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 Search for an ITEM in a Linked List
  • 12. Search for an ITEM in a Linked List
  • 13. Insert an Item Inserting a Node at the Beginning of a Linked List Step 1: IF AVAIL = NULL 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
  • 14. Insert an Item Inserting a Node at the Beginning of a Linked List
  • 15. Insert an Item Inserting a Node at the End of a Linked List Step 1: IF AVAIL = NULL 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
  • 16. Insert an Item Inserting a Node at the End of a Linked List
  • 17. Inserting a Node After a Given Node in a Linked List // using search algo Step 1: IF AVAIL = NULL 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 PTR = START Step 6: Repeat Step 3 while PTR != NULL Step 7: IF VAL = PTR->DATA SET POS = PTR SET NEW_NODE->NEXT = PTRNEXT PTR->NEXT = NEW_NODE and Exit ELSE SET PTR = PTR->NEXT [END OF IF] [END OF LOOP] Step 8: If POS = NULL then Write “Item not found” Step 9: Exit
  • 18. Insert an Item Inserting a Node After a Given Node in a Linked List
  • 19. Insert an Item Inserting a Node Before a Given Node in a Linked List Step 1: IF AVAIL = NULL 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: if PTR->DATA = NUM SET NEW_NODE-> NEXT = START SET START = NEW_NODE and EXIT Step 7:Repeat while PTR->DATA != NUM SET PREPTR = PTR SET PTR = PTR->NEXT [END OF LOOP] Step 8: SET NEW_NODE->NEXT = PREPTRNEXT Step 9: PREPTR->NEXT = NEW_NODE Step 10: EXIT
  • 20. Delete an Item Deleting the First Node from a Linked List Step 1: IF START = NULL Write UNDERFLOW Go to Step 5 [END OF IF] Step 2: SET PTR = START Step 3: SET START = START->NEXT Step 4: FREE PTR or SET PTR -> NEXT = AVAIL and AVAIL = PTR Step 5: EXIT
  • 21. Delete an Item Deleting the Last Node from a Linked List 1.IF START=NULL Print Underflow and Exit 2.Set PTR=START and PREPTR=START 3.Repeat 4 While PTR->LINK!=NULL 4.1.Set PREPTR=PTR 4.2.Set PTR=PTR->LINK 5.If PTR==START Set START=NULL 6.Else PREPTR->LINK=NULL 7.PTR->LINK=AVAIL and AVAIL=PTR 8.EXIT
  • 22. Delete an Item Deleting the Last Node from a Linked List
  • 23. Delete an Item Deleting the Node After a Given Node in a Linked List 1: IF START = NULL Write UNDERFLOW go to step 8 2: set PTR = START 3: while PTR->DATA !=KEY SET PTR= PTR->NEXT end of loop 4.TEMP=PTR->NEXT 5: SET PTR->NEXT =(PTR->NEXT)->NEXT 6:SET TEMP -> NEXT = AVAIL 7:.AVAIL=TEMP 8: EXIT
  • 24. Delete an Item Deleting the Node After a Given Node in a Linked List
  • 25. Deleting the node after a Given Node in a Linked List Step 1: IF START = NULL Write UNDERFLOW Go to Step 10 [END OF IF] Step 2: SET PTR = START Step 3: SET PREPTR = PTR Step 4: Repeat Steps 5 and 6 while PREPTR->DATA != NUM Step 5: SET PREPTR = PTR Step 6: SET PTR = PTR->NEXT [END OF LOOP] Step 7: SET TEMP = PTR Step 8: SET PREPTR->NEXT = PTR->NEXT Step 9: FREE TEMP or SET TEMP -> LINK = AVAIL and AVAIL = TEMP Step 10: EXIT
  • 26. Delete the given node step1: if start =NULL Write: Underflow and exit Step 2: SET ptr=start; Step3: if start->info == key SET start=start->link goto step 6 Step4: repeat while ptr!=NULL && ptr->info!=key 4.1 SET pptr=ptr; 4.2 SET ptr=ptr->link; Step5: SET pptr->link=ptr->link; Step6: SET PTR -> LINK = AVAIL and AVAIL = PTR Step 7: EXIT
  • 27. Circular Linked List Circular Linked-List Traversal Step 1: [INITIALIZE] SET PTR = START Step 2: Apply Process to PTR->DATA Step 3: PTR = PTR->NEXT Step 4: Repeat Steps 5 and 6 while PTR != START Step 5: Apply Process to PTR->DATA Step 6: SET PTR = PTR->NEXT [END OF LOOP] Step 7: EXIT
  • 28. Circular Linked List Inserting a Node at the Beginning of a Circular Linked List
  • 29. Inserting a Node at the Beginning of a Circular Linked List
  • 30. Inserting a Node at the End of a Circular Linked List
  • 31. Inserting a Node at the End of a Circular Linked List
  • 32. Deleting the First Node from a Circular Linked List
  • 33. Deleting the First Node from a Circular Linked List
  • 34. Deleting the Last Node from a Circular Linked List
  • 35. Deleting the Last Node from a Circular Linked List
  • 36. Header Linked Lists  Header linked list is a linked list which always contains a special node called the Header Node, at the beginning of the list.  It has two types: a) Grounded Header List Last Node Contains the NULL Pointer b) Circular Header List Last Node Points Back to the Header Node 36 Header linked list Grounded Header linked list Circular Header linked list
  • 37. Grounded Header Link List  A grounded header list is a header list where the last node contains the null pointer.  The term “grounded” comes from the fact that many texts use the electrical ground symbol to indicate the null pointer. Header Node Start Figure: Grounded Header Link List
  • 38. Circular Header Linked List  A circular header Link list is a header list where the last node points back to the header node.  The chains do not indicate the last node and first node of the link list.  In this case, external pointers provide a frame reference because last node of a circular link list does not contain null pointer. Header Node Figure: Circular Header Link List Start
  • 39. Benefit of using Header Node  One way to simplify insertion and deletion is never to insert an item before the first or after the last item and never to delete the first node  You can set a header node at the beginning of the list containing a value smaller than the smallest value in the data set  You can set a trailer node at the end of the list containing a value larger than the largest value in the data set.  These two nodes, header and trailer, serve merely to simplify the insertion and deletion algorithms and are not part of the actual list.  The actual list is between these two nodes.
  • 40. Two-way lists  A two-way list is a linear collection of data elements, called nodes, where each node N is divided into three parts:  Information field  Forward Link which points to the next node  Backward Link which points to the previous node  The starting address or the address of first node is stored in START / FIRST pointer .  Another pointer can be used to traverse list from end. This pointer is called END or LAST.
  • 41. Two-way lists(cont…)  Every node (except the last node) contains the address of the next node, and every node (except the first node) contains the address of the previous node.  A two-way list (doubly linked list) can be traversed in either direction.
  • 42. Representations of Two-way lists Start X 4 2 10 Last Data Field Prev Pointer Next Pointer X
  • 43. Traversing a doubly-LL  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
  • 44. Traversing from end.  Step 1: [INITIALIZE] SET PTR = END  Step 2: Repeat Steps 3 and 4 while PTR != NULL  Step 3: Apply Process to PTR->DATA  Step 4: SET PTR = PTR->Prev  [END OF LOOP]  Step 5: EXIT
  • 45. Insert an Item Inserting a Node at the Beginning of a Doubly Linked List Step 1: IF AVAIL = NULL Write OVERFLOW Go to Step 9 [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 -> PREV = NEW_NODE Step 8: SET START = NEW_NODE Step 9: EXIT
  • 46. Inserting a Node at the End of a Doubly Linked List Step 1: IF AVAIL = NULL 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: SET NEW_NODE -> PREV = PTR Step 11: EXIT
  • 47. Step 1: IF AVAIL = NULL 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: Repeat Step 7 while PTR -> DATA != NUM Step 7: SET PTR = PTR -> NEXT [END OF LOOP] Step 8: SET NEW_NODE -> NEXT = PTR -> NEXT Step 9: SET NEW_NODE -> PREV = PTR Step 10: SET PTR -> NEXT -> PREV = NEW_NODE Step 11: SET PTR -> NEXT = NEW_NODE Step 12: EXIT Inserting a Node After a Given Node in a Doubly Linked List
  • 48. Inserting a Node After a Given Node in a Doubly Linked List
  • 49. Step 1: IF AVAIL = NULL 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: Repeat Step 7 while PTR -> DATA != NUM Step 7: SET PTR = PTR -> NEXT [END OF LOOP] Step 8: SET NEW_NODE -> PREV=PTR->PREV Step 9: SET NEW_NODE -> NEXT= PTR Step 9: SET PTR-> PREV -> NEXT = NEW_NODE Step 10: SET PTR -> PREV = NEWNODE Step 12: EXIT Inserting a Node Before a Given Node in a Doubly Linked List
  • 50. Step 1: IF START = NULL 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 Delete an Item Deleting the First Node from a Doubly Linked List
  • 51. Delete an Item Deleting the Last Node from a Doubly Linked List Step 1: IF START = NULL Write UNDERFLOW Go to Step 7 [END OF IF] Step 2: SET PTR = START Step 3: Repeat Step 4 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
  • 52. Delete an Item Deleting the Node After a Given Node from a Doubly Linked List
  • 53. Step 1: IF START = NULL 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
  • 54. Deletion in 2-way Doubly LL  DELTWL(INFO,FORW,BACK,START,AVAIL,LOC)  1.SET FORW[BACK[LOC]]=FORW[LOC]  BACK[FORW[LOC]]=BACK[LOC]  2. SET FORW[LOC]=AVAIL and AVAIL=LOC  3.Exit
  • 55. Insertion in 2-way Doubly LL  INSTTWL(INFO,FORW,BACK,START,AVAIL,LOCA,L OCB,ITEM)  1. IF AVAIL=NULL Set OVERFLOW and Exit  2. SET NEW=AVAIL and AVAIL=FORW[AVAIL], INFO[NEW]=ITEM  3.SET FORW[LOCA]=NEW,FORW[NEW]=LOCB,  BACK[LOCB]=NEW, BACK[NEW]=LOCA  4.Exit