Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to push an element onto the stack.
DSA C
void push(int stack[], int *top, int value, int max_size) {
if (*top < max_size - 1) {
*top = *top [1] 1;
stack[*top] = value;
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' to update the top index.
Forgetting to update the top before assigning the value.
✗ Incorrect
To push an element, we increase the top index by 1 before assigning the value.
2fill in blank
mediumComplete the condition to check if the stack is full before pushing.
DSA C
if (*top [1] max_size - 1) { // Stack is full }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '>=' which can cause out of bounds errors.
Using '<' which checks for not full.
✗ Incorrect
The stack is full when top equals max_size - 1.
3fill in blank
hardFix the error in updating the top index during push.
DSA C
void push(int stack[], int *top, int value, int max_size) {
if (*top < max_size - 1) {
*top [1] *top + 1;
stack[*top] = value;
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which causes no change to *top.
Using '-=' which decreases top incorrectly.
✗ Incorrect
Use '=' to assign the incremented value to *top, not '==' which is a comparison.
4fill in blank
hardFill both blanks to complete the push function with overflow check.
DSA C
void push(int stack[], int *top, int value, int max_size) {
if (*top [1] max_size - 1) {
printf("Stack overflow\n");
return;
}
*top [2] *top + 1;
stack[*top] = value;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' in overflow check which is incorrect.
Using '==' to update top instead of assignment.
✗ Incorrect
Check if top equals max_size - 1 for overflow, then assign incremented top with '='.
5fill in blank
hardFill all three blanks to implement push with overflow check and update.
DSA C
void push(int stack[], int *top, int value, int max_size) {
if (*top [1] max_size - 1) {
printf("Stack overflow\n");
return;
}
*top [2] *top [3] 1;
stack[*top] = value;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' in overflow check.
Using '+=' instead of '=' and '+' separately.
✗ Incorrect
Check overflow with '==', assign top with '=', and increment by '+ 1'.
