Bird
0
0
DSA Cprogramming~10 mins

Dequeue 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->prev = NULL;
    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 input data.
Using the pointer variable instead of the data value.
2fill in blank
medium

Complete the code to insert a node at the front of the dequeue.

DSA C
void insertFront(struct Dequeue* dq, int data) {
    struct Node* temp = newNode(data);
    if (dq->front == NULL) {
        dq->front = dq->rear = temp;
    } else {
        temp->next = dq->front;
        dq->front->prev = [1];
        dq->front = temp;
    }
}
Drag options to blanks, or click blank then click option'
Adq->rear
BNULL
Ctemp
Ddq->front
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev pointer to NULL or rear instead of the new node.
Not updating the prev pointer at all.
3fill in blank
hard

Fix the error in the code to delete a node from the rear of the dequeue.

DSA C
void deleteRear(struct Dequeue* dq) {
    if (dq->rear == NULL) return;
    struct Node* temp = dq->rear;
    dq->rear = dq->rear->prev;
    if (dq->rear != NULL) {
        dq->rear->next = [1];
    } else {
        dq->front = NULL;
    }
    free(temp);
}
Drag options to blanks, or click blank then click option'
Adq->rear
Btemp
Cdq->front
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next pointer to temp or rear instead of NULL.
Not updating the next pointer after deletion.
4fill in blank
hard

Fill both blanks to insert a node at the rear of the dequeue correctly.

DSA C
void insertRear(struct Dequeue* dq, int data) {
    struct Node* temp = newNode(data);
    if (dq->rear == NULL) {
        dq->front = dq->rear = temp;
    } else {
        dq->rear->next = [1];
        temp->prev = [2];
        dq->rear = temp;
    }
}
Drag options to blanks, or click blank then click option'
Atemp
Bdq->front
Cdq->rear
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up prev and next pointers.
Setting pointers to NULL incorrectly.
5fill in blank
hard

Fill all three blanks to delete a node from the front of the dequeue correctly.

DSA C
void deleteFront(struct Dequeue* dq) {
    if (dq->front == NULL) return;
    struct Node* temp = dq->front;
    dq->front = dq->front->[1];
    if (dq->front != NULL) {
        dq->front->[2] = [3];
    } else {
        dq->rear = NULL;
    }
    free(temp);
}
Drag options to blanks, or click blank then click option'
Anext
Bprev
CNULL
Dfront
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next to move front pointer.
Not setting prev pointer of new front to NULL.
Setting pointers to wrong nodes.