CJCoding With Joseph
15free / daySign inCreate account

Add a Node to the End

addFirst() is already written for you. Appending is the expensive twin: with no tail pointer you must walk the whole chain to reach the last node, so addLast() is O(n).

Requirements:
1. addLast(int value) appends a node holding value to the back of the list.
2. When the list is empty the new node becomes head.
3. Otherwise walk to the node whose next is null and link the new node there.

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:

10 -> 20 -> 30 -> null
3

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

Hints4 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.