Bird
0
0
DSA Cprogramming~10 mins

Queue Implementation Using Array in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A0
BNULL
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing front to 0 causes confusion between empty and first element.
Using NULL is invalid for integer variables.
2fill in blank
medium

Complete 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'
Afront
BMAX_SIZE
Crear
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing rear to front instead of MAX_SIZE.
Using size variable which may not be defined.
3fill in blank
hard

Fix 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'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + causes rear to move backward.
Using * or / causes incorrect pointer arithmetic.
4fill in blank
hard

Fill 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'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using - causes front to move backward.
Using * or / causes wrong index calculation.
5fill in blank
hard

Fill 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'
A+
B<=
C<
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= may cause printing beyond the rear element.
Using - or other operators breaks the loop logic.