CJCoding With Joseph
15free / daySign inCreate account

Keep the Tail Pointer Honest

A TailedIntList holds head, tail and a size counter so that appending costs O(1) instead of the walk IntList needs. The price is that every insert must leave all three fields correct.

Requirements:
1. addLast(int value) appends in O(1) using tail, with no walking at all.
2. addFirst(int value) inserts at the front, and must ALSO set tail when the list was empty.
3. Both methods increase size by one.

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:

true
10 -> 20 -> 30 -> null
3
30

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