Bird
0
0
DSA Cprogramming~10 mins

Stack vs Array Direct Use Why We Need Stack Abstraction in DSA C - Interactive Comparison Practice

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

Complete the code to declare an array to use as a stack with size 5.

DSA C
int stack[[1]];
Drag options to blanks, or click blank then click option'
A5
B0
C10
Dstack
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as size causes no space for elements.
Using variable name instead of size inside brackets.
2fill in blank
medium

Complete the code to initialize the top of the stack to -1 (empty).

DSA C
int top = [1];
Drag options to blanks, or click blank then click option'
A5
B-1
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting top to 0 means stack appears full at start.
Using positive numbers incorrectly.
3fill in blank
hard

Fix the error in the push function to correctly add an element to the stack.

DSA C
void push(int stack[], int *top, int value) {
    if (*top < 4) {
        *top = *top [1] 1;
        stack[*top] = value;
    }
}
Drag options to blanks, or click blank then click option'
A+
B*
C-
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction causes overwriting previous elements.
Using multiplication or division is incorrect here.
4fill in blank
hard

Fill both blanks to correctly pop an element from the stack and update top.

DSA C
int pop(int stack[], int *top) {
    if (*top == [1]) {
        return -1; // stack empty
    }
    int value = stack[*top];
    *top = *top [2] 1;
    return value;
}
Drag options to blanks, or click blank then click option'
A-1
B0
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Checking top == 0 means stack appears empty too early.
Incrementing top after pop is wrong.
5fill in blank
hard

Fill all three blanks to check if stack is full and print a message.

DSA C
if (*top [1] [2]) {
    printf("Stack is [3]\n");
}
Drag options to blanks, or click blank then click option'
A==
B4
Cfull
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of equality.
Printing wrong message.