Recall & Review
beginner
What does it mean when a stack is empty?
A stack is empty when it has no elements inside it. This means the top pointer is at -1 or no items have been pushed yet.
Click to reveal answer
beginner
How do you check if a stack is full in an array implementation?
You check if the top pointer is equal to the maximum size minus one. If yes, the stack is full and cannot hold more elements.
Click to reveal answer
beginner
What is the role of the 'top' variable in a stack?
The 'top' variable keeps track of the index of the last added element in the stack. It helps to know where to push or pop elements.
Click to reveal answer
beginner
Why is it important to check if a stack is empty before popping?
If you pop from an empty stack, it causes an error because there is no element to remove. Checking prevents this mistake.
Click to reveal answer
beginner
What happens if you try to push an element into a full stack?
Trying to push into a full stack causes an overflow error because there is no space left to add new elements.
Click to reveal answer
What condition checks if a stack is empty?
✗ Incorrect
When top is -1, it means no elements are in the stack, so it is empty.
How do you know a stack is full in an array of size maxSize?
✗ Incorrect
If top equals maxSize - 1, the stack has reached its capacity.
What is the initial value of top in an empty stack?
✗ Incorrect
Top starts at -1 to indicate the stack is empty.
What error occurs if you pop from an empty stack?
✗ Incorrect
Popping from an empty stack causes underflow because there is nothing to remove.
What should you do before pushing an element onto the stack?
✗ Incorrect
You must check if the stack is full to avoid overflow errors.
Explain how to check if a stack is empty or full using the 'top' variable.
Think about the position of 'top' relative to stack size.
You got /3 concepts.
Describe what happens if you try to pop from an empty stack or push into a full stack.
Consider what errors prevent safe stack operations.
You got /3 concepts.
