Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a doubly linked list node struct.
DSA C++
struct Node {
int data;
Node* prev;
Node* [1];
};Attempts:
3 left
💡 Hint
Common Mistakes
Using 'previous' instead of 'next' for the forward pointer.
Using unrelated names like 'child' or 'link'.
✗ Incorrect
The pointer to the next node in a doubly linked list is commonly named 'next'.
2fill in blank
mediumComplete the constructor to initialize the node's data and pointers.
DSA C++
Node(int val) {
data = val;
prev = nullptr;
[1] = nullptr;
}Attempts:
3 left
💡 Hint
Common Mistakes
Initializing 'prev' twice and forgetting 'next'.
Using incorrect pointer names.
✗ Incorrect
The 'next' pointer should be initialized to nullptr in the constructor.
3fill in blank
hardFix the error in the code that creates a new node and sets its data.
DSA C++
Node* newNode = new Node([1]);
newNode->prev = nullptr;
newNode->next = nullptr;Attempts:
3 left
💡 Hint
Common Mistakes
Passing nullptr or NULL instead of an integer value.
Passing zero which is valid but less clear than a meaningful number.
✗ Incorrect
The constructor expects an integer value; '5' is a valid integer to initialize data.
4fill in blank
hardFill both blanks to correctly link two nodes in a doubly linked list.
DSA C++
first->next = [1]; second->prev = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up 'prev' and 'next' pointers.
Assigning nullptr instead of node pointers.
✗ Incorrect
The first node's next pointer should point to the second node, and the second node's prev pointer should point back to the first node.
5fill in blank
hardFill all three blanks to create a doubly linked list with three nodes connected properly.
DSA C++
Node* first = new Node(1); Node* second = new Node(2); Node* third = new Node(3); first->next = [1]; second->prev = [2]; second->next = [3]; third->prev = second;
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to link the second node's next pointer.
Mixing up which node pointer to assign.
✗ Incorrect
The first node's next points to second, second's prev points to first, and second's next points to third.
