CJCoding With Joseph
15free / daySign inCreate account

Count the Nodes

This IntList stores no counter, so size() has to find out the hard way: start a cursor at head and follow next until it runs off the end, counting as it goes.

Requirements:
1. size() returns the number of nodes currently in the list.
2. An empty list returns 0.

The Node class is provided - do not rename it and do not add public to it, because a Java source file may contain only one public class.

Do NOT write a main method.

Expected Output:

0
3
4
5 -> 10 -> 20 -> 30 -> null

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
Data Structures & AlgorithmsLinked Lists
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.