Professional Documents
Culture Documents
A328928575 - 26699 - 3 - 2022 - 5. Linked List (Insertion)
A328928575 - 26699 - 3 - 2022 - 5. Linked List (Insertion)
By
Ravi Kant Sahu
Asst. Professor
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Insertion into a Linked List
Types of insertion:
• Insertion at the beginning
• Insertion between two nodes
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Checking the Available List
AVAIL
ITEM Ø
Free-Storage List
NEW
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Insertion at the beginning of Linked List
START
ITEM
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Insertion Algorithm (Beginning of the list)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Insertion after a given node
START
ITEM
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Insertion Algorithm (After a given node)
INSLOC (INFO, LINK, START, AVAIL, LOC, ITEM)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Insertion into a sorted Linked List
• If ITEM is to be inserted into a sorted linked list. Then ITEM must be
inserted between nodes A and B such that:
A->INFO < ITEM < B->INFO
• First of all find the location of Node A
• Then insert the node after Node A.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Review Questions
• What is the condition for the list being empty?
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Review Questions
• Correct the following algorithm such that ptr contains the
address of the last node:
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)