Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as size causes no space for elements.
Using variable name instead of size inside brackets.
✗ Incorrect
The stack array size must be 5 to hold 5 elements.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting top to 0 means stack appears full at start.
Using positive numbers incorrectly.
✗ Incorrect
Top is set to -1 to indicate the stack is empty initially.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction causes overwriting previous elements.
Using multiplication or division is incorrect here.
✗ Incorrect
We add 1 to top to move to the next free position before inserting.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking top == 0 means stack appears empty too early.
Incrementing top after pop is wrong.
✗ Incorrect
Check if top is -1 (empty). Decrement top by 1 after popping.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than instead of equality.
Printing wrong message.
✗ Incorrect
Stack is full when top equals 4 (last index). Print 'full' message.
