A. Change condition to if (top >= size) to correctly detect overflow
B. Change condition to if (top == size - 1) to avoid overflow
C. Initialize top to 1 instead of 0 to fix indexing
D. Replace top++ with ++top to fix increment order
Solution
Step 1: Analyze overflow condition
Since array indices go from 0 to size-1, top == size means stack is full; condition should catch top >= size to prevent overflow.
Step 2: Check other options
Changing to size - 1 is incorrect because top points to next free slot; initializing top to 1 or changing increment order is unrelated.
Final Answer:
Change condition to if (top >= size) to correctly detect overflow -> Option A
Quick Check:
Overflow check = top >= size [OK]
Hint: Overflow when top index reaches or exceeds size [OK]
Common Mistakes:
Using top == size - 1 instead of top >= size
Incorrect top initialization
Misunderstanding increment order
5. Given a stack implemented using an array with size 5, which sequence of operations will result in the stack containing elements [5, 10, 15] from bottom to top?