Complete the code to check if the stack is empty.
function isEmpty(stack) {
return stack.length [1] 0;
}The stack is empty when its length is exactly 0, so we use '==' to compare.
Complete the code to check if the stack is full given max size.
function isFull(stack, maxSize) {
return stack.length [1] maxSize;
}The stack is full when its length equals the maximum size, so we use '=='.
Fix the error in the function that checks if the stack is empty.
function checkEmpty(stack) {
if (stack.length [1] 0) {
return true;
} else {
return false;
}
}The condition should check if length equals zero to confirm stack is empty.
Fill both blanks to check if the stack is neither empty nor full.
function isNotEmptyOrFull(stack, maxSize) {
return stack.length [1] 0 && stack.length [2] maxSize;
}The stack is not empty if length is not zero, and not full if length is less than maxSize.
Fill all three blanks to return 'Empty', 'Full', or 'Normal' based on stack state.
function stackStatus(stack, maxSize) {
if (stack.length [1] 0) {
return 'Empty';
} else if (stack.length [2] maxSize) {
return 'Full';
} else {
return [3];
}
}Check if length equals zero for empty, equals maxSize for full, else return 'Normal'.
