Linked List (Deletion)
Linked List (Deletion)
Linked List (Deletion)
By
Ravi Kant Sahu
Asst. Professor
• Deletion Algorithm
– Deleting the Node following a given Node
– Deleting a Node with a given ITEM of Information
• Review Questions
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Deletion from a Linked List
Types of Deletion:
• Deleting the node following a given node
• Deleting the Node with a given ITEM of Information.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Deletion from Linked List
START
ITEM Ø
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Maintaining the AVAIL List
• After the deletion of a node from the list, memory space of
node N will be added to the beginning of AVAIL List.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Work Space
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Deleting the Node Following a given Node
DEL (INFO, LINK, START, AVAIL, LOC, LOCP)
3. EXIT.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Deleting the Node with a given ITEM of
Information
DELETE (INFO, LINK, START, AVAIL, ITEM)
1. Call FIND_B (INFO, LINK, START, ITEM, LOC, LOCP)
[Find the Location of node N and its preceding node]
2. If LOC = NULL, then: Write: ITEM not in LIST and EXIT.
3. [Delete node].
If LOCP = NULL, then:
Set START = LINK [START]. [Delete First node]
Else:
Set LINK [LOCP] = LINK [LOC].
[End of If Structure.]
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Work Space
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Header Linked List
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Header Linked List
A header linked list which always contains a special
node, called the header node, at the beginning of the
list.
START
Ø
HEADER NODE
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Header Linked List
• This header node need not represent the same type of data that
succeeding nodes do.
• Header node can access the data of all the nodes in the linked
list.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Types of Header Linked List
A Grounded header list is a header list where the last node
contains the null pointer.
Note:
• Unless otherwise stated or implied, header list will always be circular
list.
• Accordingly, in such a case, the header node also acts as a sentinel
indicating the end of the list.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
START
Ø
HEADER NODE
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
START
HEADER NODE
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
• If Link [START] = NULL,
then, Grounded Header List is Empty.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Traversing a Circuar Header List
Algorithm (Traversing a Circular Header list)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Use of Header Linked List
• Header Linked lists are frequently used for maintaining
Polynomials in memory.
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)