Bird
0
0
DSA Cprogramming~10 mins

Push Using Linked List Node 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];
Drag options to blanks, or click blank then click option'
Adata
BNULL
Cnode
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning NULL or next pointer to data field.
Using an undefined variable instead of data.
2fill in blank
medium

Complete the code to link the new node to the current head of the list.

DSA C
newNode->next = [1];
Drag options to blanks, or click blank then click option'
ANULL
Bhead
Cdata
DnewNode
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to NULL which breaks the list.
Setting next to newNode itself causing a cycle.
3fill in blank
hard

Fix the error in updating the head pointer to the new node.

DSA C
*head_ref = [1];
Drag options to blanks, or click blank then click option'
ANULL
Bdata
Chead
DnewNode
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning data or NULL to head_ref instead of newNode.
Assigning head which is old pointer, not new node.
4fill in blank
hard

Fill both blanks to complete the push function that inserts a new node at the beginning.

DSA C
void push(struct Node** head_ref, int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = [1];
    newNode->next = [2];
    *head_ref = newNode;
}
Drag options to blanks, or click blank then click option'
Adata
Bhead_ref
C*head_ref
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using head_ref instead of *head_ref for next pointer.
Assigning NULL to next which loses the rest of the list.
5fill in blank
hard

Fill all three blanks to complete the push function with memory allocation, data assignment, and linking.

DSA C
void push(struct Node** head_ref, int data) {
    struct Node* newNode = (struct Node*)malloc(sizeof([1]));
    newNode->data = [2];
    newNode->next = [3];
    *head_ref = newNode;
}
Drag options to blanks, or click blank then click option'
ANode
Bdata
C*head_ref
Dstruct Node
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Node' without struct keyword in sizeof.
Assigning wrong variable to data or next pointers.