Bird
0
0
DSA Cprogramming~10 mins

Why Stack Exists and What Problems It Solves in DSA C - Test Your Knowledge

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

Complete the code to push an element onto the stack.

DSA C
void push(int stack[], int *top, int value) {
    stack[++[1]] = value;
}
Drag options to blanks, or click blank then click option'
Avalue
Btop
C*top
Dstack
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of '*top' causes incorrect pointer usage.
Assigning value before incrementing top.
2fill in blank
medium

Complete the code to pop an element from the stack.

DSA C
int pop(int stack[], int *top) {
    if (*top == -1) return -1; // stack empty
    return stack[[1]--];
}
Drag options to blanks, or click blank then click option'
A*top
Bstack
Ctop
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using prefix decrement causes wrong element to be returned.
Using 'top' instead of '*top'.
3fill in blank
hard

Fix the error in the stack overflow check condition.

DSA C
int isFull(int top, int maxSize) {
    return [1] >= maxSize - 1;
}
Drag options to blanks, or click blank then click option'
A*top
Btop
Cstack
DmaxSize
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*top' causes compilation error.
Comparing with maxSize instead of maxSize - 1.
4fill in blank
hard

Fill both blanks to check if the stack is empty and return the top element safely.

DSA C
int safePop(int stack[], int *top) {
    if (*top [1] -1) return -1;
    return stack[[2]--];
}
Drag options to blanks, or click blank then click option'
A<=
B==
C*top
Dtop
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '==' causes wrong empty check.
Using 'top' instead of '*top'.
5fill in blank
hard

Fill all three blanks to implement a function that returns the current top element without popping it.

DSA C
int peek(int stack[], int *top) {
    if (*top [1] -1) return -1;
    return stack[[2]];
    // top remains [3]
}
Drag options to blanks, or click blank then click option'
A==
B>
C*top
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '==' causes wrong empty check.
Modifying top in peek causes stack corruption.