algo_09
Problem Statement
Problem Statement
Write an algorithm to insert a node after a special key value.
Algorithm
procedure insertAfterKey(head, key)
begin
current ← head;
while(current ≠ NULL && info(current) ≠ key)
current ← next(current);
endwhile
if(current ≠ NULL)
write("Enter the value: ");
read(val);
newNode ← getnode();
info(newNode) ← val;
next(newNode) ← next(current);
next(current) ← newNode;
else
write("Key not found in the list.");
endif
end procedure1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17