Search

Monday, February 17, 2014
0 comments

Deletion Opration in Linked List for Data Structure in C Programming

6:03 AMMonday, February 17, 2014
Deletion
Removing a node from the linked list is called deletion. Get the Information of the node, which is to be     removed. Compare the Information with the INFO of ROOT . If it is equal update ROOT with LINK of ROOT, otherwise set pervious location PLOC with ROOT and location LOC with LINK of ROOT. Compare the information with that of INFO of LOC, if it is not equal then copy LOC in PLOC and update LOC with LINK of LOC. If the node is found then come out and set LINK of PLOC with LINK of LOC, and the deletion is over. Add the deleted node to Free Pool, by assigning LINK of LOC with AVAIL and AVAIL with LOC.
       If the PLOC is assigned with LOC, then when the list is traversed automatically the node with address LOC is skipped, that is why PLOC is used in this case.

         For example consider the below linked list:


       If a node with information 20 is to be deleted, the operation is done as shown below:


       The original list after deletion of the node with information 20 is shown e:


Algorithm to delete a node from the Linked List:

DELETIONLL(ROOT, INFO)
If INFO=ROOT-->INFO Then:
LOC<--ROOT
ROOT<--ROOT-->LINK
Else:
 PLOC<--ROOT
 LOC<--ROOT-->LINK
Repeat While LOC< >NULL AND INFO< >LOC-->INFO
 PLOC<--LOC
 LOC<--LOC-->LINK
[End of While]
PLOC--> LINK<-- LOC-->LINK
[End of If]
[Following statements to add deleted node to free pool]
 LOC-->LINK<--AVAIL
AVAIL<--LOC
Exit.


Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top