Push onto a Linked-Node Stack
easyQuestion 415This stack has no array and no capacity - it is a chain of nodes, and the field top points at the front of that chain. Only push is missing, and it can never fail, so it returns nothing.
Requirements:
1. Complete push(int value) so the new node becomes the front of the chain.
2. The new node's next must point at the old top before top is moved.
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
30 -> 20 -> 10 -> null 30 3
= 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.