Stack•Easy
Push Operation
Stack Push Operation

The Push operation inserts a new element onto the top of the stack.
Key Rules
- Overflow Check: Before adding a new element, you must verify if the stack has reached its allocated capacity limit (
top >= MAX - 1). If it is full, an Overflow condition is met, and the push is rejected. - Increment Top: If space remains, increment the index pointer
topby 1 to point to the next vacant slot. - Store Value: Place the new element at the newly incremented index
arr[top].
Visually
Before Push(40): After Push(40):
Index [3]: [ Empty ] Index [3]: [ 40 ] ◄top
Index [2]: [ 30 ] ◄top Index [2]: [ 30 ]
Index [1]: [ 20 ] Index [1]: [ 20 ]
Index [0]: [ 10 ] Index [0]: [ 10 ]