algo_075
Problem Statement
Problem Statement
Write an algorithm to concatenate two singly linked lists.
Algorithm
procedure ConcatenateLists(head1, head2)
begin
if head1 = NULL then
return(head2)
endif
if head2 = NULL then
return(head1)
endif
ptr ← head1
while next(ptr) != NULL do
ptr ← next(ptr)
endwhile
next(ptr) ← head2
return(head1)
end procedure1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19