← Back to Data Structures & Algorithms
Question 435
Finish the Linked-Node Stack
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. CompleteisEmpty()using the top field. 2. Completepeek()so it returns the front value and leaves the chain alone. 3. Completepop()so it returns the front value and unlinks that node. 4.peek()andpop()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
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.