96. Implement Stack Using Array with Push and Pop Operations

In embedded systems where dynamic memory is not available, stacks are typically implemented using static arrays and index tracking.

Your task is to:

  • Implement a stack using a fixed-size array
  • Support 2 operations:
    • push x → Push value x into the stack
    • pop → Pop and print the top value from the stack
  • Print "Stack Overflow" if trying to push when full
  • Print "Stack Underflow" if trying to pop when empty


Example Input Format

First line: n (number of operations)

Next n lines: push x or pop

 

Example-1

Input:
5  
push 10  
push 20  
pop  
pop  
pop

Output:
20  
10  
Stack Underflow


Example-2

Input:
4  
pop  
push 5  
pop  
pop

Output:
Stack Underflow  
5  
Stack Underflow


 

Loading...

Input

5 push 10 push 20 pop pop pop

Expected Output

20 10 Stack Underflow