algo_04
Problem Statement
Problem Statement
Write an algorithm to count number of nodes in a singly linked list.
Algorithm
procedure count(head)
begin
count = 0;
if(head = NULL)
write(count);
else
ptr ← head;
while(ptr ≠ NULL)
count ← count + 1;
ptr ← next(ptr);
end while
write(count);
endif
end procedure1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14