Bird
0
0
DSA Cprogramming~10 mins

Queue Implementation Using Linked List 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 create a new node with given data.

DSA C
struct Node* newNode(int data) {
    struct Node* temp = (struct Node*)malloc(sizeof(struct Node));
    temp->data = [1];
    temp->next = NULL;
    return temp;
}
Drag options to blanks, or click blank then click option'
Adata
BNULL
Ctemp
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning NULL or 0 instead of the data value.
Using the wrong variable name.
2fill in blank
medium

Complete the code to check if the queue is empty.

DSA C
int isEmpty(struct Queue* q) {
    return (q->front == [1]);
}
Drag options to blanks, or click blank then click option'
Aq->rear
B0
CNULL
Dq->front
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing front to rear instead of NULL.
Using 0 instead of NULL in pointer comparison.
3fill in blank
hard

Fix the error in the enqueue function to correctly update the rear pointer.

DSA C
void enqueue(struct Queue* q, int data) {
    struct Node* temp = newNode(data);
    if (q->rear == NULL) {
        q->front = temp;
        q->rear = [1];
        return;
    }
    q->rear->next = temp;
    q->rear = temp;
}
Drag options to blanks, or click blank then click option'
Atemp
Bq->front
CNULL
Dq->rear
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning q->front or NULL to q->rear.
Not updating q->rear at all.
4fill in blank
hard

Fill both blanks to correctly dequeue an element and update the queue pointers.

DSA C
int dequeue(struct Queue* q) {
    if (isEmpty(q))
        return -1;
    struct Node* temp = q->front;
    int data = temp->data;
    q->front = [1];
    if (q->front == NULL)
        q->rear = [2];
    free(temp);
    return data;
}
Drag options to blanks, or click blank then click option'
Aq->front->next
BNULL
Ctemp->next
Dq->rear->next
Attempts:
3 left
💡 Hint
Common Mistakes
Using q->front->next before updating front pointer.
Not setting rear to NULL when queue becomes empty.
5fill in blank
hard

Fill all three blanks to print all elements in the queue from front to rear.

DSA C
void displayQueue(struct Queue* q) {
    struct Node* temp = [1];
    while (temp != [2]) {
        printf("%d -> ", [3]);
        temp = temp->next;
    }
    printf("NULL\n");
}
Drag options to blanks, or click blank then click option'
Aq->front
BNULL
Ctemp->data
Dq->rear
Attempts:
3 left
💡 Hint
Common Mistakes
Starting from rear instead of front.
Looping until temp equals rear instead of NULL.
Printing temp instead of temp->data.