Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the stack is empty.
DSA C
int isEmpty(int top) {
return top [1] -1;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison '=='
Checking if top is greater than -1 instead of equal
✗ 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 given MAX size.
DSA C
int isFull(int top) {
return top [1] MAX - 1;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' instead of '=='
Comparing top with MAX instead of MAX - 1
✗ Incorrect
The stack is full when the top index equals MAX - 1.
3fill in blank
hardFix the error in the function that checks if the stack is empty.
DSA C
int isEmpty(int top) {
if (top [1] -1) {
return 1;
} else {
return 0;
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' inside if condition
Confusing '==' with '='
✗ Incorrect
The condition should use '==' to compare top with -1, not '=' which assigns.
4fill in blank
hardFill both blanks to correctly check if the stack is full or empty.
DSA C
int checkStack(int top) {
if (top [1] -1) {
return 0; // empty
} else if (top [2] MAX - 1) {
return 1; // full
}
return -1; // neither
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison '=='
Using '!=' or '>' which give wrong results
✗ Incorrect
Use '==' to compare top with -1 for empty and with MAX - 1 for full.
5fill in blank
hardFill all three blanks to implement a function that returns a string status of the stack.
DSA C
const char* stackStatus(int top) {
if (top [1] -1) {
return "Empty";
} else if (top [2] MAX - 1) {
return "Full";
} else if (top [3] -1 && top [3] MAX - 1) {
return "Has Space";
}
return "Invalid";
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' instead of '!=' in last condition
Mixing assignment '=' with comparison operators
✗ Incorrect
Check if top equals -1 for empty, equals MAX - 1 for full, and is not equal to either for having space.
