Algorithm to count the number of nodes in a linked list Steps:
1. Start
2. Set a temporary pointer to the first node and counter to 0.
3. Repeat steps 4 and 5 until the pointer reaches null
4. Increment the counter
5. move the temporary pointer to the next node
6. Return the counter value
7. End
Method to count for the number of nodes in a linked list
int count (Node ptr_start)
{
Node a = new Node(ptr_start);
int c=0;
while (a!=null)
{ c++; a=a.next;
}
return c:
}