algo_004.md (400B)
1 # algo_004 2 3 ### Problem Statement 4 5 > Write an algorithm to count number of nodes in a singly linked list. 6 7 ## Algorithm 8 ``` 9 procedure count(head) 10 begin 11 count = 0; 12 if(head = NULL) 13 write(count); 14 else 15 ptr ← head; 16 while(ptr ≠ NULL) 17 count ← count + 1; 18 ptr ← next(ptr); 19 end while 20 write(count); 21 endif 22 end procedure 23 ```