For a stack implemented with an array of size MAX where top starts at −1, which condition indicates the stack is full?
Correct answer A. top == MAX − 1
Explanation
With 0-based indexing and top starting at −1, each push increments top before storing, so the last valid slot is index MAX − 1. When top equals MAX − 1 another push would overflow. top == −1 is the empty condition, and top == MAX would already be past the end of the array, which is too late to detect overflow safely.
Answer checked How we write and check questions
Discussion