Go/Lists
From charlesreid1
To use lists in Go, use the "container/lists" package. This will import a linked list object. import "container/list"
Link: https://golang.org/pkg/container/list/
package main
import (
"fmt"
"container/list"
)
func main() {
// Initialize list
l := list.New()
// Populate list
e4 := l.PushBack(4)
e1 := l.PushFront(1)
// State of list is [1, 4]
l.InsertBefore(3, e4)
l.InsertAfter(2, e1)
// State of list is [1, 2, 3, 4]
// Iterate over list
for e := l.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value)
}
}
Flags
| Go notes on Go
Go/Strings · Go/Arrays · Go/Slices
Go/Lists · Go/Maps · Go/Stacks · Go/Queues
Go/Naming Conventions · Go/Design Patterns
Go/Timing · Go/Profiling · Go/Benchmarking
Go/Tests · Go/Travis CI · Go/Makefiles
our vim + go setup uses custom solarized colors for Golang
|