Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the stack is empty.
DSA Java
public boolean 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 Java
public boolean isFull() {
return top [1] maxSize - 1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using < or > instead of == causes incorrect 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 method that checks if the stack is empty.
DSA Java
public boolean isEmpty() {
if (top [1] -1) {
return true;
} else {
return false;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' in if condition.
Using '!=' will invert the logic.
✗ Incorrect
Use '==' to compare values in conditions, '=' is assignment.
4fill in blank
hardFill both blanks to complete the method that checks if the stack is full.
DSA Java
public boolean isFull() {
if (top [1] maxSize [2] 1) {
return true;
} else {
return false;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' changes the logic.
Using '!=' causes wrong condition.
✗ Incorrect
The condition checks if top equals maxSize minus 1.
5fill in blank
hardFill all three blanks to complete the method that checks if the stack is empty or full and returns a string.
DSA Java
public String checkStack() {
if (top [1] -1) {
return "Empty";
} else if (top [2] maxSize [3] 1) {
return "Full";
} else {
return "Not full or empty";
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong results.
Using '+' instead of '-' changes the full condition.
✗ Incorrect
Use '==' to compare top with -1 and maxSize - 1 to check empty and full states.
