import ( "container/list" "fmt" ) func main() { l := list.New() l.PushBack("hello") l.PushBack("world") first := l.Front() fmt.Println(first.Value) }
hello
import ( "container/list" "fmt" ) func main() { l := list.New() l.PushBack("hello") l.PushBack("world") l.PushFront("goodbye") first := l.Front() fmt.Println(first.Value) }
goodbyeThis code creates a new list, adds three elements to it, and then retrieves the first element using the Front method. Because the last element added was pushed to the front of the list using the PushFront method, the first element retrieved is "goodbye". In summary, the container/list package library in Go provides a simple implementation for doubly linked lists, and the List Front method is used to retrieve the first element of the list.