Complete the code to create a new node with the given value.
newNode := &Node{data: val, next: [1]The new node's next pointer should point to the current head before insertion.
Complete the code to link the new node to the current head.
newNode.next = [1]The new node should point to the current head to insert at the beginning.
Fix the error in updating the head pointer after insertion.
head = [1]After insertion, head must point to the new node.
Fill both blanks to complete the function that inserts a new node at the beginning.
func insertAtBeginning(head *Node, val int) *Node {
newNode := &Node{data: val, next: [1]
head = [2]
return head
}The new node's next should point to the current head, then head is updated to newNode.
Fill all three blanks to complete the linked list insertion and print the list.
func insertAndPrint(head *Node, val int) *Node {
newNode := &Node{data: val, next: [1]
head = [2]
current := head
for current != [3] {
fmt.Print(current.data, " -> ")
current = current.next
}
fmt.Println("null")
return head
}Link newNode to head, update head to newNode, then traverse until current is nil to print.
