Practice mode Data Structures

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.