Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
13.6k views
in Computer by (69.2k points)

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

1 Answer

+1 vote
by (69.8k points)
selected by
 
Best answer

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

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...