To move through a 'standard' linked list in C++ we need an iterator and we also need to know when the iteration will end because there are no more nodes.
So initially we pass the counter function a pointer to the first node and also a pointer to the position just after the last node.
The total number of nodes is 1 plus the number of nodes from the next position to the end. So we increment the pointer and call the counter function recursively until eventually we get to the end when the stack unwinds and we're left with 0 plus a series of 1's which add up to the number of nodes in the linked list.
VulpesPosted Sep 28, 2014, 7:08 AM
So initially we pass the counter function a pointer to the first node and also a pointer to the position just after the last node.
The total number of nodes is 1 plus the number of nodes from the next position to the end. So we increment the pointer and call the counter function recursively until eventually we get to the end when the stack unwinds and we're left with 0 plus a series of 1's which add up to the number of nodes in the linked list.
Joe WilsonPosted Sep 28, 2014, 2:45 AM
I don't understand the codes below.
VulpesPosted Sep 27, 2014, 3:42 PM