Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the front index of the queue.
DSA C
int front = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing front to 0 causes confusion between empty and first element.
Using NULL is invalid for integer variables.
✗ Incorrect
The front index is initialized to -1 to indicate the queue is empty.
2fill in blank
mediumComplete the code to check if the queue is full.
DSA C
if (rear == [1] - 1) { printf("Queue is full\n"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing rear to front instead of MAX_SIZE.
Using size variable which may not be defined.
✗ Incorrect
The queue is full when rear reaches MAX_SIZE - 1, the last index of the array.
3fill in blank
hardFix the error in the enqueue function to correctly add an element.
DSA C
void enqueue(int queue[], int *rear, int value) {
if (*rear == MAX_SIZE - 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 rear to move backward.
Using * or / causes incorrect pointer arithmetic.
✗ Incorrect
To add an element, increment rear by 1 before assigning the value.
4fill in blank
hardFill the blank to correctly dequeue an element and update front.
DSA C
int dequeue(int queue[], int *front, int rear) {
if (*front == rear) {
printf("Queue is empty\n");
return -1;
} else {
*front = *front [1] 1;
return queue[*front];
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using - causes front to move backward.
Using * or / causes wrong index calculation.
✗ Incorrect
Increment front by 1 to remove the front element and return it.
5fill in blank
hardFill all three blanks to implement a function that prints all elements in the queue.
DSA C
void printQueue(int queue[], int front, int rear) {
if (front == rear) {
printf("Queue is empty\n");
} else {
for (int i = front [1] 1; i [2] rear; i [3] 1) {
printf("%d -> ", queue[i]);
}
printf("NULL\n");
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= may cause printing beyond the rear element.
Using - or other operators breaks the loop logic.
✗ Incorrect
The loop starts from front + 1, runs while i < rear, and increments i by 1 each time to print all elements.
