Bird
0
0
DSA Cprogramming~10 mins

Create and Initialize 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 define the struct for a doubly linked list node.

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

Complete the code to allocate memory for a new node.

DSA C
Node* newNode = (Node*) malloc(sizeof([1]));
Drag options to blanks, or click blank then click option'
ANode*
Bnode
Cstruct Node
DNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'struct Node' when typedef is already used.
Using lowercase 'node' which is undefined.
3fill in blank
hard

Fix the error in the code to initialize the new node's pointers to NULL.

DSA C
newNode->prev = [1];
newNode->next = NULL;
Drag options to blanks, or click blank then click option'
ANULL
B0
Cnullptr
Dnil
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'nullptr' which is C++ keyword.
Using 'nil' which is not valid in C.
4fill in blank
hard

Fill both blanks to assign data and initialize pointers in the new node.

DSA C
newNode->data = [1];
newNode->prev = [2];
Drag options to blanks, or click blank then click option'
Avalue
BNULL
C0
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'data' variable which may not exist.
Using 0 instead of NULL for pointers.
5fill in blank
hard

Fill all three blanks to create a function that initializes a new doubly linked list node.

DSA C
Node* createNode(int [1]) {
    Node* newNode = (Node*) malloc(sizeof([2]));
    if (newNode != NULL) {
        newNode->data = [3];
        newNode->prev = NULL;
        newNode->next = NULL;
    }
    return newNode;
}
Drag options to blanks, or click blank then click option'
Avalue
BNode
Cval
Dstruct Node
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names.
Using 'struct Node' in malloc when typedef is used.