← Back to Data Structures & Algorithms
Question 412
Pop and Peek on an Array Stack
Pop and Peek on an Array Stack
The array stack can already push and display itself. The two ways of reading the top item are missing, and they differ in exactly one way: one of them moves top and one leaves it alone. Requirements: 1. Completepop()so it returns the top value and removes it. 2. Completepeek()so it returns the top value and leaves the stack untouched. 3. Both return -1 on an empty stack. Never print from inside the class. Do NOT write a main method.
Expected Output:
30 30 30 20 Stack: 10
= 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.