Bird
0
0
DSA Cprogramming~5 mins

Check if Stack is Empty or Full in DSA C - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Atop == maxSize
Btop == -1
Ctop == 0
Dtop > maxSize
How do you know a stack is full in an array of size maxSize?
Atop == maxSize - 1
Btop == -1
Ctop == 0
Dtop > maxSize
What is the initial value of top in an empty stack?
A1
B0
C-1
DmaxSize
What error occurs if you pop from an empty stack?
ASyntax error
BOverflow
CSegmentation fault
DUnderflow
What should you do before pushing an element onto the stack?
ACheck if the stack is full
BCheck if the stack is empty
CReset top to -1
DPop an element first
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.