CJCoding With Joseph
15free / daySign inCreate account

Finish the Linked-Node Stack

push and the display are written. The three methods that read or remove the front of the chain are not, and they have to agree about what an empty chain looks like.

Requirements:
1. Complete isEmpty() using the top field.
2. Complete peek() so it returns the front value and leaves the chain alone.
3. Complete pop() so it returns the front value and unlinks that node.
4. peek() and pop() both return -1 when the stack is empty.

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
-1
-1
15 -> 8 -> 4 -> null
false
15
15
15
8 -> 4 -> null

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

Hints4 available
Topics:
Data Structures & AlgorithmsStacks
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.