Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of 'value' to push.
Not incrementing the top before assignment.
✗ Incorrect
We push the given value onto the stack by incrementing top and assigning value.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of '*top' causing wrong memory access.
Decrementing top before accessing the value.
✗ Incorrect
We return the value at the current top and then decrement top.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causing subtraction.
Using '*' or '/' causing wrong operation.
✗ Incorrect
The '+' operator performs addition between val1 and val2.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing top instead of &top causing incorrect stack behavior.
Passing *top causing type mismatch.
✗ Incorrect
We pass the address of top (&top) to pop to update the top index correctly.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing top or *top causing incorrect stack updates.
Passing stack instead of &top causing errors.
✗ Incorrect
We pass &top to push and pop so that the top index is updated correctly.
