3. What is the output of the following Go code that deletes the last node from a doubly linked list?
package main
import "fmt"
type Node struct {
data int
prev *Node
next *Node
;
}
type DoublyLinkedList struct {
head *Node
tail *Node
;
}
func (dll *DoublyLinkedList) DeleteFromEnd() {
if dll.tail == nil {
return
}
if dll.tail.prev == nil {
dll.head = nil
dll.tail = nil
return
}
dll.tail = dll.tail.prev
dll.tail.next = nil
}
func (dll *DoublyLinkedList) Print() {
current := dll.head
for current != nil {
fmt.Print(current.data, " -> ")
current = current.next
}
fmt.Println("null")
}
func main() {
n1 := &Node{data: 1}
n2 := &Node{data: 2}
n3 := &Node{data: 3}
n1.next = n2
n2.prev = n1
n2.next = n3
n3.prev = n2
dll := DoublyLinkedList{head: n1, tail: n3}
dll.DeleteFromEnd()
dll.Print()
}