Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Go
newNode := &Node{data: [1]Attempts:
3 left
💡 Hint
Common Mistakes
Using position instead of value for the new node data.
Assigning nil instead of the value.
✗ Incorrect
We create a new node with the data field set to the value to insert.
2fill in blank
mediumComplete the code to check if the position is 1 (insert at head).
DSA Go
if [1] == 1 {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the value instead of position.
Using the new node or head instead of position.
✗ Incorrect
We check if the position to insert is 1, meaning at the head.
3fill in blank
hardFix the error in updating the previous pointer of the old head node.
DSA Go
if head != nil { head.[1] = newNode }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head.next instead of head.prev.
Trying to set data or pos fields.
✗ Incorrect
The previous pointer of the old head should point to the new node.
4fill in blank
hardFill both blanks to move the current pointer to the next node in the list.
DSA Go
current = current.[1] if current != nil { current.[2] = newNode }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' to move forward instead of 'next'.
Setting current.next instead of current.prev.
✗ Incorrect
We move current to its next node, then set current.prev to the new node.
5fill in blank
hardFill all three blanks to insert the new node between current and current.next.
DSA Go
newNode.[1] = current.[2] newNode.[3] = current current.[2] = newNode
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up next and prev pointers.
Not updating current.next to newNode.
✗ Incorrect
Set newNode.next to current.next, newNode.prev to current, and current.next to newNode.
