I have a linked list of type generic and I want to count how many nodes there are in the linked list....How, conceptually, should I think of approaching this? I can't seem to wrap my head around it.

Printable View

- 10-17-2011, 06:10 AMcolerelmHow would I count number of nodes in linked list?
I have a linked list of type generic and I want to count how many nodes there are in the linked list....How, conceptually, should I think of approaching this? I can't seem to wrap my head around it.

- 10-17-2011, 06:22 AMJunkyRe: How would I count number of nodes in linked list?
Maintain an instance variable. Each time a node is added increment it by one. Each time a node is deleted decrement it by one.

- 10-17-2011, 06:26 AMpbrockway2Re: How would I count number of nodes in linked list?Quote:

How, conceptually, should I think of approaching this?

Now it's a relatively simple matter to count the number of places you visit as you follow the clues. If you stick to orange juice.