Bird
0
0
DSA Cprogramming~10 mins

Doubly Linked List Structure and Node Design 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 declare a node structure for a doubly linked list.

DSA C
typedef struct Node {
    int data;
    struct Node* prev;
    struct Node* [1];
} Node;
Drag options to blanks, or click blank then click option'
Anext
Bprevious
Clink
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'previous' instead of 'next' for the forward pointer.
Using unrelated names like 'child' or 'link'.
2fill in blank
medium

Complete the code to create a new node dynamically.

DSA C
Node* createNode(int value) {
    Node* newNode = (Node*)malloc(sizeof([1]));
    if (newNode == NULL) return NULL;
    newNode->data = value;
    newNode->prev = NULL;
    newNode->next = NULL;
    return newNode;
}
Drag options to blanks, or click blank then click option'
ANode*
Bnode
Cstruct Node
DNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'node' which is undefined.
Using 'struct Node' when typedef is used.
Using pointer type 'Node*' inside sizeof.
3fill in blank
hard

Fix the error in the function to initialize a doubly linked list node.

DSA C
void initNode(Node* node, int val) {
    node->data = val;
    node->prev = NULL;
    node->[1] = NULL;
}
Drag options to blanks, or click blank then click option'
Anext
Bprevious
Clink
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'previous' which is not declared.
Using unrelated pointer names.
4fill in blank
hard

Fill both blanks to correctly link two nodes in a doubly linked list.

DSA C
void linkNodes(Node* first, Node* second) {
    first->[1] = second;
    second->[2] = first;
}
Drag options to blanks, or click blank then click option'
Anext
Bprev
Cprevious
Dlink
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'next' and 'prev' pointers.
Using undefined pointer names like 'previous' or 'link'.
5fill in blank
hard

Fill all four blanks to insert a new node between two existing nodes.

DSA C
void insertBetween(Node* prevNode, Node* newNode, Node* nextNode) {
    newNode->[1] = nextNode;
    newNode->[2] = prevNode;
    prevNode->[3] = newNode;
    nextNode->[4] = newNode;
}
Drag options to blanks, or click blank then click option'
Anext
Bprev
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to update prevNode's next pointer.
Forgetting to update nextNode's prev pointer.
Mixing up 'next' and 'prev' pointers.