The container/list package implements a doubly linked list.
package main // w w w . j a v a 2 s.com import ("fmt" ; "container/list") func main() { var x list.List x.PushBack(1) x.PushBack(2) x.PushBack(3) for e := x.Front(); e != nil; e=e.Next() { fmt.Println(e.Value.(int)) } }
Values are appended to the list using PushBack.
We loop over each item in the list by getting the first element, and following all the links until we reach nil.