Go: container/list Index | Examples | Files

package list

import "container/list"

Package list implements a doubly linked list.

To iterate over a list (where l is a *List):

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

Code:play 

// Create a new list and put some numbers in it.
l := list.New()
e4 := l.PushBack(4)
e1 := l.PushFront(1)
l.InsertBefore(3, e4)
l.InsertAfter(2, e1)

// Iterate through list and print its contents.
for e := l.Front(); e != nil; e = e.Next() {
    fmt.Println(e.Value)
}

Output:

1
2
3
4

Index

Examples

Package Files

list.go

type Element Uses

type Element struct {

    // The value stored with this element.
    Value interface{}
    // contains filtered or unexported fields
}

Element is an element of a linked list.

func (*Element) Next Uses

func (e *Element) Next() *Element

Next returns the next list element or nil.

func (*Element) Prev Uses

func (e *Element) Prev() *Element

Prev returns the previous list element or nil.

type List Uses

type List struct {
    // contains filtered or unexported fields
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func New Uses

func New() *List

New returns an initialized list.

func (*List) Back Uses

func (l *List) Back() *Element

Back returns the last element of list l or nil.

func (*List) Front Uses

func (l *List) Front() *Element

Front returns the first element of list l or nil.

func (*List) Init Uses

func (l *List) Init() *List

Init initializes or clears list l.

func (*List) InsertAfter Uses

func (l *List) InsertAfter(v interface{}, mark *Element) *Element

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified.

func (*List) InsertBefore Uses

func (l *List) InsertBefore(v interface{}, mark *Element) *Element

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified.

func (*List) Len Uses

func (l *List) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*List) MoveAfter Uses

func (l *List) MoveAfter(e, mark *Element)

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified.

func (*List) MoveBefore Uses

func (l *List) MoveBefore(e, mark *Element)

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified.

func (*List) MoveToBack Uses

func (l *List) MoveToBack(e *Element)

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified.

func (*List) MoveToFront Uses

func (l *List) MoveToFront(e *Element)

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified.

func (*List) PushBack Uses

func (l *List) PushBack(v interface{}) *Element

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*List) PushBackList Uses

func (l *List) PushBackList(other *List)

PushBackList inserts a copy of an other list at the back of list l. The lists l and other may be the same.

func (*List) PushFront Uses

func (l *List) PushFront(v interface{}) *Element

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List) PushFrontList Uses

func (l *List) PushFrontList(other *List)

PushFrontList inserts a copy of an other list at the front of list l. The lists l and other may be the same.

func (*List) Remove Uses

func (l *List) Remove(e *Element) interface{}

Remove removes e from l if e is an element of list l. It returns the element value e.Value.

Package list is imported by 2778 packages. Updated 2017-02-17. Refresh now. Tools for package owners.