StackEasy

Pop Operation

Stack Pop Operation

Pop Operation

The Pop operation removes and returns the top element of the stack.

Key Rules

  1. Underflow Check: Before removing an element, you must verify if the stack is already empty (top < 0). If it contains zero elements, a Stack Underflow condition occurs, and the pop operation is rejected.
  2. Access Value: If elements exist, retrieve the element value stored at arr[top].
  3. Decrement Top: Decrement the index pointer top by 1 to logically remove the element.

Visually

Before Pop():             After Pop():
  Index [2]: [  30   ] ◄top  Index [2]: [ Empty ]
  Index [1]: [  20   ]      Index [1]: [  20   ] ◄top
  Index [0]: [  10   ]      Index [0]: [  10   ]