Bird
0
0
DSA Cprogramming~10 mins

Insert at End of Doubly 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 = (struct Node*)malloc(sizeof(struct Node));
newNode->data = [1];
newNode->next = NULL;
newNode->prev = NULL;
Drag options to blanks, or click blank then click option'
Adata
BNULL
Chead
Dtemp
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning NULL or other pointers instead of the data value.
Forgetting to assign the data field.
2fill in blank
medium

Complete the code to check if the list is empty.

DSA C
if (*head == [1]) {
    *head = newNode;
    return;
}
Drag options to blanks, or click blank then click option'
Atemp
BNULL
Chead
DnewNode
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing head to newNode or other pointers.
Using assignment '=' instead of comparison '=='.
3fill in blank
hard

Fix the error in the loop that finds the last node.

DSA C
struct Node* temp = *head;
while (temp->[1] != NULL) {
    temp = temp->next;
}
Drag options to blanks, or click blank then click option'
Aprev
Bdata
Cnext
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using temp->prev which moves backward.
Checking temp->data instead of pointers.
4fill in blank
hard

Fill both blanks to link the new node at the end.

DSA C
temp->next = [1];
[2]->prev = temp;
Drag options to blanks, or click blank then click option'
AnewNode
Bhead
Ctemp
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Linking to head or temp incorrectly.
Not updating both next and prev pointers.
5fill in blank
hard

Fill all three blanks to complete the insert at end function.

DSA C
void insertEnd(struct Node** head, int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = [1];
    newNode->next = NULL;
    newNode->prev = NULL;

    if (*head == [2]) {
        *head = newNode;
        return;
    }

    struct Node* temp = *head;
    while (temp->next != NULL) {
        temp = temp->next;
    }

    temp->next = [3];
    newNode->prev = temp;
}
Drag options to blanks, or click blank then click option'
Adata
BNULL
CnewNode
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to dereference head pointer.
Linking temp->next to wrong node.
Not setting newNode->prev correctly.