Finish the Linked-Node Stack
mediumQuestion 435push 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, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
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.