Documentation ¶
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 ¶
package main import ( "container/list" "fmt" ) func main() { // 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 and print its contents. for e := l.Front(); e != nil; e = e.Next() { fmt.Println(e.Value) } }
Output: 1 2 3 4
Index ¶
- type A
- type List
- func (l *List) Back() *ListElement
- func (l *List) Front() *ListElement
- func (l *List) Init() *List
- func (l *List) InsertAfter(v A, mark *ListElement) *ListElement
- func (l *List) InsertBefore(v A, mark *ListElement) *ListElement
- func (l *List) Len() int
- func (l *List) MoveToBack(e *ListElement)
- func (l *List) MoveToFront(e *ListElement)
- func (l *List) PushBack(v A) *ListElement
- func (l *List) PushBackList(other *List)
- func (l *List) PushFront(v A) *ListElement
- func (l *List) PushFrontList(other *List)
- func (l *List) Remove(e *ListElement) A
- type ListElement
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
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 (*List) Back ¶
func (l *List) Back() *ListElement
Back returns the last element of list l or nil.
func (*List) Front ¶
func (l *List) Front() *ListElement
Front returns the first element of list l or nil
func (*List) InsertAfter ¶
func (l *List) InsertAfter(v A, mark *ListElement) *ListElement
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 ¶
func (l *List) InsertBefore(v A, mark *ListElement) *ListElement
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) MoveToBack ¶
func (l *List) MoveToBack(e *ListElement)
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 ¶
func (l *List) MoveToFront(e *ListElement)
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 ¶
func (l *List) PushBack(v A) *ListElement
PushBack inserts a new element e with value v at the back of list l and returns e.
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 (*List) PushFront ¶
func (l *List) PushFront(v A) *ListElement
PushFront inserts a new element e with value v at the front of list l and returns e.
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 (*List) Remove ¶
func (l *List) Remove(e *ListElement) A
Remove removes e from l if e is an element of list l. It returns the element value e.Value.
type ListElement ¶
type ListElement struct { // The value stored with this element. Value A // contains filtered or unexported fields }
ListElement is an element of a linked list.
func (*ListElement) Next ¶
func (e *ListElement) Next() *ListElement
Next returns the next list element or nil.
func (*ListElement) Prev ¶
func (e *ListElement) Prev() *ListElement
Prev returns the previous list element or nil.