Complete the code to check if the stack is empty.
int isEmpty(int top) {
return top [1] -1;
}The stack is empty when the top index is equal to -1.
Complete the code to check if the stack is full given MAX size.
int isFull(int top) {
return top [1] MAX - 1;
}The stack is full when the top index equals MAX - 1.
Fix the error in the function that checks if the stack is empty.
int isEmpty(int top) {
if (top [1] -1) {
return 1;
} else {
return 0;
}
}The condition should use '==' to compare top with -1, not '=' which assigns.
Fill both blanks to correctly check if the stack is full or empty.
int checkStack(int top) {
if (top [1] -1) {
return 0; // empty
} else if (top [2] MAX - 1) {
return 1; // full
}
return -1; // neither
}Use '==' to compare top with -1 for empty and with MAX - 1 for full.
Fill all three blanks to implement a function that returns a string status of the stack.
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";
}Check if top equals -1 for empty, equals MAX - 1 for full, and is not equal to either for having space.
