Given a linked list whose typical node consists of an INFO and LINK field. Formulate an algorithm which will count the number of nodes in the list.
Function: COUNT_NODES(FIRST)
- This function counts number of nodes of the linked list and returns COUNT.
- FIRST is a pointer to the first element of a Singly linked linear list.
- Typical node contains INFO and LINK fields.
- SAVE is a Temporary pointer variable.
- [Is list Empty]
IF FIRST=NULL
THEN Return(COUNT)
- [Initialize loop for a last node to update count]
SAVE<--FIRST
- [Go for end of list]
Repeat while LINK(SAVE)!=NULL
SAVE<--LINK(SAVE)
COUNT<--COUNT+1
- [Return Count]
Return(COUNT)