3. Given the following Go code for inserting at the end of a circular linked list, what will be the printed list after inserting 4?
type Node struct {
data int
next *Node
}
func insertEnd(last *Node, data int) *Node {
newNode := &Node{data: data}
if last == nil {
newNode.next = newNode
return newNode
}
newNode.next = last.next
last.next = newNode
return newNode
}
func printList(last *Node) {
if last == nil {
fmt.Println("List is empty")
return
}
temp := last.next
for {
fmt.Printf("%d -> ", temp.data)
temp = temp.next
if temp == last.next {
break
}
}
fmt.Println("null")
}
func main() {
var last *Node
last = insertEnd(last, 1)
last = insertEnd(last, 2)
last = insertEnd(last, 3)
last = insertEnd(last, 4)
printList(last)
}