From charlesreid1

Revision as of 14:27, 13 December 2018 by Admin (talk | contribs)

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 "container/list"

func main() {

    // Initialize list
    l := list.New()

    // Populate list
    e4 := l.PushBack(4)
    e1 := l.PushFront(1)
    l.InsertBefore(3, e4)
    l.InsertAfter(2, e1)

    // Iterate over list
    for e := l.Front(); e != nil; e = e.Next() {
	// do something with e.Value
    }
}

Flags