Slideshow

Monday, 25 February 2013



258 .Write an algorithm to insert a node after a given node in a linear linked list. 

Ans:
Suppose we are given a value of LOC where LOC is the location of the node
'A' in the linked list.
The following algorithm inserts an 'ITEM' into LIST (given Linked list) so that
‘TTEM' follows node 'A'.

1. If AVAIL = NULL , Then write overflow and exit
2. set NEW = AVAIL and AVAIL=:link[AVAIL] [remove first node from
AVAIL LIST]
3. set INFO[NEW]=ITEM [copies new data into new node]
4. if LOC=NULL then [insert as first node]
set LINK[NEW]= START and START = NEW
else [insert after node with
location LOC]
set LINK[NEW]=LINK[LOC] and LINK[LOC]=NEW
[end of if structure]
5. exit

No comments:

Post a Comment