Practice
Stack Push and Pop
HARDStacks12 marks
Implement a stack of up to five integers using an array and a top pointer.
For each operation:
Pis followed by a value. Push it and outputTRUE, or outputFALSEif the stack is full.Opops and outputs the top value, or outputs-1if the stack is empty.
Input: An operation count followed by operations and push values. Output: One result per operation.
Example:
Input: 4
P 10
P 20
O
O
Output: TRUE
TRUE
20
10
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: LIFO order
Inputs: 4, P, 10, P, 20, O, O
Expected: TRUE
TRUE
20
10
Test 2: Empty stack
Inputs: 2, O, O
Expected: -1
-1