Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the queue.
DSA C
void enqueue(int value) {
if (rear == MAX - 1) {
printf("Queue is full\n");
} else {
rear = rear [1] 1;
queue[rear] = value;
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causes the rear to move backward.
Using '*' or '/' operators is incorrect for index increment.
✗ Incorrect
To add an element, we increase the rear index by 1 using '+'.
2fill in blank
mediumComplete the code to remove an element from the queue.
DSA C
int dequeue() {
if (front > rear) {
printf("Queue is empty\n");
return -1;
} else {
int value = queue[front];
front = front [1] 1;
return value;
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' instead of '+' causes the front to move backward.
Using '*' or '/' operators is incorrect for index increment.
✗ Incorrect
To remove an element, we increase the front index by 1 using '+'.
3fill in blank
hardFix the error in the condition that checks if the queue is empty.
DSA C
if (front [1] rear) { printf("Queue is empty\n"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '==' causes wrong empty queue detection.
Using '!=' is incorrect for empty condition.
✗ Incorrect
The queue is empty when front is greater than rear, so use '>'.
4fill in blank
hardFill both blanks to correctly initialize the queue indices.
DSA C
int front = [1]; int rear = [2];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting both to -1 causes front > rear to fail initially (-1 not > -1).
Using MAX is out of bounds.
✗ Incorrect
front starts at 0 and rear at -1 to indicate an empty queue.
5fill in blank
hardFill the blanks to check if the queue is full.
DSA C
if (rear [1] MAX [2] 1) { printf("Queue is full\n"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' causes wrong index calculation.
Using '>' instead of '==' causes incorrect full check.
✗ Incorrect
The queue is full when rear equals MAX - 1 (rear == MAX - 1).
