import ( "container/list" "fmt" ) func main() { l := list.New() l.PushFront(3) l.PushFront(2) l.PushFront(1) for e := l.Front(); e != nil; e = e.Next() { fmt.Println(e.Value) } }
import ( "container/list" "fmt" ) func main() { l := list.New() l.PushFront("world") l.PushFront("hello") for e := l.Front(); e != nil; e = e.Next() { fmt.Println(e.Value) } }This code creates a new list, adds strings "hello" and "world" to the front using PushFront, and then iterates over the list to print out its contents. The "container/list" package is part of the standard Go library.