Bird
0
0
DSA Cprogramming~10 mins

Check if Stack is Empty or Full in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A>
B==
C!=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison '=='
Checking if top is greater than -1 instead of equal
2fill in blank
medium

Complete 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'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' instead of '=='
Comparing top with MAX instead of MAX - 1
3fill in blank
hard

Fix 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'
A==
B=
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' inside if condition
Confusing '==' with '='
4fill in blank
hard

Fill 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'
A==
B=
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment '=' instead of comparison '=='
Using '!=' or '>' which give wrong results
5fill in blank
hard

Fill 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'
A==
B!=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' instead of '!=' in last condition
Mixing assignment '=' with comparison operators