Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the stack is empty.
DSA C#
public bool IsEmpty() {
return top [1] -1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using > or < instead of == causes wrong empty check.
Using != will return true when stack is not empty.
✗ Incorrect
The stack is empty when the top index is equal to -1.
2fill in blank
mediumComplete the code to check if the stack is full.
DSA C#
public bool IsFull() {
return top [1] maxSize - 1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using < or > instead of == causes wrong full check.
Using != will return true when stack is not full.
✗ Incorrect
The stack is full when the top index equals maxSize - 1.
3fill in blank
hardFix the error in the condition to check if the stack is empty.
DSA C#
public bool IsEmpty() {
return top [1] -1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking top == 0 instead of top == -1.
Using !=, >= or <= is incorrect for empty check.
✗ Incorrect
The correct check for empty stack is top == -1. A common error is checking against 0 instead.
4fill in blank
hardFill both blanks to correctly check if the stack is full.
DSA C#
public bool IsFull() {
return top [1] maxSize [2] 1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' causes wrong index calculation.
Using '!=' instead of '==' causes wrong full check.
✗ Incorrect
The stack is full when top equals maxSize minus 1, so use '==' and '-'.
5fill in blank
hardFill all three blanks to check if the stack is empty or full.
DSA C#
public bool IsEmptyOrFull() {
return (top [1] -1) || (top [2] maxSize [3] 1);
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong checks.
Using '+' instead of '-' causes wrong full index.
✗ Incorrect
The stack is empty if top == -1, and full if top == maxSize - 1.
