package main import ( "fmt" ) type list struct { head *item tail *item } type item struct { name string prev *item next *item } func main() { list := &list{} list.add(&item{name: "foo"}) list.add(&item{name: "bar"}) list.add(&item{name: "baz"}) list.show() } func (list *list) add(item *item) { if list.head == nil { list.head = item } else { currentItem := list.tail currentItem.next = item item.prev = list.tail item.next = list.head list.head.prev = item } list.tail = item } func (list *list) show() { currentItem := list.head if currentItem == nil { return } fmt.Printf("%+v\n", currentItem) for currentItem.next != nil { currentItem = currentItem.next if currentItem == list.head { break } fmt.Printf("%+v\n", currentItem) } }