Complete the code to create a new node with the given value.
newNode := &Node{data: [1], next: nil}The new node's data field should be assigned the variable value which holds the value to insert.
Complete the code to check if the list is empty before inserting.
if head == [1] { head = newNode return head }
In Go, the zero value for pointers is nil. Checking if head == nil means the list is empty.
Fix the error in the loop that finds the last node.
current := head for current.next [1] nil { current = current.next }
The loop should continue while current.next is not nil, so use !=.
Fill both blanks to correctly link the new node at the end.
current.next = [1] return [2]
Assign newNode to current.next to link it at the end, then return head as the list start.
Fill all three blanks to complete the tail insert function.
func InsertAtEnd(head *Node, value int) *Node {
newNode := &Node{data: [1], next: nil}
if head == [2] {
head = newNode
return head
}
current := head
for current.next [3] nil {
current = current.next
}
current.next = newNode
return head
}The function creates a new node with value, checks if head is nil (empty list), then loops while current.next != nil to find the last node.
