Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA C
void push(char stack[], int *top, char 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.
Using 'stack' or 'top' incorrectly.
✗ Incorrect
We push the given value onto the stack at the incremented top index.
2fill in blank
mediumComplete the code to check if the stack is empty.
DSA C
int isEmpty(int top) {
return [1] == -1;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'stack' or 'value' instead of 'top'.
Using 'size' which is unrelated here.
✗ Incorrect
The stack is empty when 'top' is -1.
3fill in blank
hardFix the error in the pop function to return the top element and update the top index.
DSA C
char pop(char stack[], int *top) {
if (*top == -1) return '\0';
return stack[[1]--];
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'top' instead of '*top' causes wrong indexing.
Using 'stack' or '(*top)' incorrectly.
✗ Incorrect
We return the element at '*top' and then decrement '*top'.
4fill in blank
hardFill both blanks to check if the popped opening bracket matches the current closing bracket.
DSA C
int isMatchingPair(char opening, char closing) {
return (opening == [1] && closing == [2]) ||
(opening == '{' && closing == '}') ||
(opening == '[' && closing == ']');
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing opening and closing brackets.
Using double quotes instead of single quotes.
✗ Incorrect
We check if opening is '(' and closing is ')'.
5fill in blank
hardFill all three blanks to complete the main loop that checks balanced parentheses.
DSA C
for (int i = 0; i < length; i++) { if (expression[i] == [1] || expression[i] == [2] || expression[i] == [3]) { push(stack, &top, expression[i]); } else { if (isEmpty(top)) return 0; char popped = pop(stack, &top); if (!isMatchingPair(popped, expression[i])) return 0; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including closing brackets in the push condition.
Using wrong bracket characters.
✗ Incorrect
We push opening brackets '(', '[', '{' onto the stack.
