Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a node's data field as an integer.
DSA Java
class Node { int [1]; Node next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'pointer' which are not standard names for the data field.
✗ Incorrect
The standard name for the data field in a node is 'data'.
2fill in blank
mediumComplete the code to declare the pointer to the next node.
DSA Java
class Node { int data; [1] next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' or 'Node*' which are invalid in Java for node pointers.
✗ Incorrect
The 'next' pointer should be of type Node to point to the next node.
3fill in blank
hardFix the error in the constructor to assign the data field correctly.
DSA Java
class Node { int data; Node next; Node(int [1]) { data = [1]; next = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name different from the one declared causes errors.
✗ Incorrect
The constructor parameter is named 'value', so use 'value' to assign data.
4fill in blank
hardFill both blanks to complete the method that sets the next node pointer.
DSA Java
class Node { int data; Node next; void setNext([1] node) { this.[2] = node; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' as parameter type or assigning to 'data' instead of 'next'.
✗ Incorrect
The method parameter type is Node, and the field to assign is 'next'.
5fill in blank
hardFill all three blanks to complete the method that prints the node's data and next pointer status.
DSA Java
class Node { int data; Node next; void printNode() { System.out.println("Data: " + [1]); System.out.println("Has next? " + ([2] != [3])); } }
Attempts:
3 left
💡 Hint
Common Mistakes
Printing 'this' or comparing next to 'this' instead of null.
✗ Incorrect
Print the data field, check if next is not null to indicate a next node.
