Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a doubly linked list node class with data and pointers.
DSA C#
public class Node { public int data; public Node prev; public Node [1]; public Node(int data) { this.data = data; prev = null; next = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'previous' instead of 'next' for the forward pointer.
Using generic names like 'pointer' or 'link' which are not standard.
✗ Incorrect
The next pointer in a doubly linked list node is named 'next' to point to the next node.
2fill in blank
mediumComplete the code to initialize the head of the doubly linked list with a new node.
DSA C#
Node head = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using null which is not valid for int data.
Using negative numbers without reason.
✗ Incorrect
Initializing the head node with data 0 is a common simple start for demonstration.
3fill in blank
hardFix the error in the code to link the new node after the head.
DSA C#
Node newNode = new Node(5); head.[1] = newNode; newNode.prev = head;
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning newNode to head.prev which points backward.
Using non-standard names like 'link' or 'pointer'.
✗ Incorrect
To link a new node after head, assign it to head.next.
4fill in blank
hardFill both blanks to insert a new node between head and head.next.
DSA C#
Node newNode = new Node(10); newNode.prev = head; newNode.[1] = head.[2]; head.next = newNode; if (newNode.next != null) { newNode.next.prev = newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' causing incorrect links.
Using non-standard names.
✗ Incorrect
The new node's next pointer should point to head.next to insert correctly.
5fill in blank
hardFill all three blanks to create a method that initializes a doubly linked list with one node.
DSA C#
public Node InitializeList(int data) {
Node head = new Node(data);
head.[1] = null;
head.[2] = null;
return [3];
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'node' which is undefined.
Swapping prev and next pointers.
✗ Incorrect
The method sets head.prev and head.next to null and returns head.
