Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a node class with an integer data field.
DSA C#
public class Node { public int [1]; public Node next; public Node(int data) { this.data = data; this.next = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' or 'info' which are not consistent with the constructor.
Naming the field differently than the constructor parameter causing confusion.
✗ Incorrect
The field storing the integer value in the node is commonly named 'data'.
2fill in blank
mediumComplete the code to link the current node to the next node.
DSA C#
Node current = new Node(5); Node nextNode = new Node(10); current.[1] = nextNode;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists pointing backward.
Using 'link' or 'child' which are not standard pointer names here.
✗ Incorrect
The 'next' pointer links the current node to the next node in the list.
3fill in blank
hardFix the error in the constructor to correctly assign the data field.
DSA C#
public Node(int data) {
this.[1] = data;
this.next = null;
}Attempts:
3 left
💡 Hint
Common Mistakes
Assigning to a non-existent field like 'value' or 'info'.
Forgetting 'this.' causing assignment to parameter itself.
✗ Incorrect
The constructor must assign the parameter 'data' to the field named 'data'.
4fill in blank
hardFill both blanks to create a method that sets the next node.
DSA C#
public void SetNext([1] nextNode) { this.[2] = nextNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' as parameter type instead of 'Node'.
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 create a method that returns the data of the next node if it exists.
DSA C#
public int? GetNextData() {
if (this.[1] != null) {
return this.[2].[3];
}
return null;
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'prev' instead of 'next'.
Returning 'value' which is not a field in the node.
✗ Incorrect
Check if 'next' is not null, then return 'next.data'.
