Bird
0
0
DSA Cprogramming~10 mins

Evaluate Postfix Expression Using Stack 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 push a value onto the stack.

DSA C
void push(int stack[], int *top, int value) {
    stack[++(*top)] = [1];
}
Drag options to blanks, or click blank then click option'
Avalue
Bstack
Ctop
D*top
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of 'value' to push.
Not incrementing the top before assignment.
2fill in blank
medium

Complete the code to pop a value from the stack.

DSA C
int pop(int stack[], int *top) {
    return stack[[1]--];
}
Drag options to blanks, or click blank then click option'
A*top
Btop
Cstack
D(*top)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of '*top' causing wrong memory access.
Decrementing top before accessing the value.
3fill in blank
hard

Fix the error in the switch case to perform addition.

DSA C
switch (exp[i]) {
    case '+':
        res = val1 [1] val2;
        break;
    // other cases
}
Drag options to blanks, or click blank then click option'
A-
B/
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causing subtraction.
Using '*' or '/' causing wrong operation.
4fill in blank
hard

Fill both blanks to correctly pop two values for operation.

DSA C
int val2 = pop(stack, [1]);
int val1 = pop(stack, [2]);
Drag options to blanks, or click blank then click option'
Atop
B*top
C&top
Dstack
Attempts:
3 left
💡 Hint
Common Mistakes
Passing top instead of &top causing incorrect stack behavior.
Passing *top causing type mismatch.
5fill in blank
hard

Fill all three blanks to correctly evaluate the postfix expression.

DSA C
for (int i = 0; exp[i] != '\0'; i++) {
    if (isdigit(exp[i])) {
        push(stack, [1], exp[i] - '0');
    } else {
        int val2 = pop(stack, [2]);
        int val1 = pop(stack, [3]);
        // perform operation
    }
}
Drag options to blanks, or click blank then click option'
A&top
Btop
C*top
Dstack
Attempts:
3 left
💡 Hint
Common Mistakes
Passing top or *top causing incorrect stack updates.
Passing stack instead of &top causing errors.