Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given data.
DSA Java
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of the data value.
Using 'head' which is the start of the list, not the new data.
Using 'null' which means no data.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to link the new node to the current head of the list.
DSA Java
newNode.[1] = head;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' which holds the value, not the link.
Using 'prev' which is for doubly linked lists.
Using 'value' which is not a pointer.
✗ Incorrect
The 'next' pointer of the new node should point to the current head node.
3fill in blank
hardFix the error in updating the head pointer to the new node.
DSA Java
head = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to head.next which skips the new node.
Assigning head to data which is a value, not a node.
Assigning head to next which is undefined here.
✗ Incorrect
The head should now point to the new node, making it the first node in the list.
4fill in blank
hardFill both blanks to complete the push method that adds a new node at the start.
DSA Java
public void push(int data) {
Node newNode = new Node([1]);
newNode.[2] = head;
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for linking nodes.
Not updating the head pointer after linking.
✗ Incorrect
The new node is created with the data, its next points to the current head, then head is updated.
5fill in blank
hardFill all three blanks to complete the push method with clear variable names.
DSA Java
public void push(int [1]) { Node [2] = new Node([1]); [2].next = head; head = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using 'value' which is less common for parameter name.
✗ Incorrect
The method parameter is 'data', the new node variable is 'newNode', used consistently.
