...
Run Format

Package list

import "container/list"
Overview
Index
Examples

Overview ▾

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
}

Example

1
2
3
4

type Element

Element is an element of a linked list.

type Element struct {

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

func (*Element) Next

Next returns the next list element or nil.

func (e *Element) Next() *Element

func (*Element) Prev

Prev returns the previous list element or nil.

func (e *Element) Prev() *Element

type List

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

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

func New

New returns an initialized list.

func New() *List

func (*List) Back

Back returns the last element of list l or nil.

func (l *List) Back() *Element

func (*List) Front

Front returns the first element of list l or nil.

func (l *List) Front() *Element

func (*List) Init

Init initializes or clears list l.

func (l *List) Init() *List

func (*List) InsertAfter

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 (l *List) InsertAfter(v interface{}, mark *Element) *Element

func (*List) InsertBefore

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 (l *List) InsertBefore(v interface{}, mark *Element) *Element

func (*List) Len

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

func (l *List) Len() int

func (*List) MoveAfter

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 (l *List) MoveAfter(e, mark *Element)

func (*List) MoveBefore

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 (l *List) MoveBefore(e, mark *Element)

func (*List) MoveToBack

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

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

func (*List) MoveToFront

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

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

func (*List) PushBack

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

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

func (*List) PushBackList

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

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

func (*List) PushFront

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

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

func (*List) PushFrontList

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

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

func (*List) Remove

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

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