CJCoding With Joseph
15free / daySign inCreate account

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. Complete pop() so it returns the top value and removes it. 2. Complete peek() 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, so 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.