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 print its contents. for e := l.Front(); e != nil; e = e.Next() { fmt.Println(e.Value) } }
Output: 1 2 3 4
Index ¶
- type Element
- type List
- func (l *List) Back() *Element
- func (l *List) Front() *Element
- func (l *List) Init() *List
- func (l *List) InsertAfter(v interface{}, mark *Element) *Element
- func (l *List) InsertBefore(v interface{}, mark *Element) *Element
- func (l *List) Len() int
- func (l *List) MoveAfter(e, mark *Element)
- func (l *List) MoveBefore(e, mark *Element)
- func (l *List) MoveToBack(e *Element)
- func (l *List) MoveToFront(e *Element)
- func (l *List) PushBack(v interface{}) *Element
- func (l *List) PushBackList(other *List)
- func (l *List) PushFront(v interface{}) *Element
- func (l *List) PushFrontList(other *List)
- func (l *List) Remove(e *Element) interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element struct { // The value stored with this element. Value interface{} // 存储的值 // contains filtered or unexported fields }
Element is an element of a linked list. Element 这是一个 list 中存储的元素
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. List 表示一个双向链表
func (*List) Back ¶
Back returns the last element of list l or nil if the list is empty. Back 返回最后一个元素
func (*List) Front ¶
Front returns the first element of list l or nil if the list is empty. Front 返回第一个元素
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. The mark must not be nil. InsertBefore 在特定元素后面插入
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. The mark must not be nil. InsertBefore 在特定元素前面插入
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. The element and mark must not be nil. MoveToFront 将元素移到特定元素后面
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. The element and mark must not be nil. MoveToFront 将元素移到特定元素前面
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. The element must not be nil. MoveToBack 将元素移到链表尾部
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. The element must not be nil. MoveToFront 将元素移到链表头部
func (*List) PushBack ¶
PushBack inserts a new element e with value v at the back of list l and returns e. PushBack 在列表后面插入
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. They must not be nil. PushBackList 在链表尾部插入另一个链表的拷贝
func (*List) PushFront ¶
PushFront inserts a new element e with value v at the front of list l and returns e. PushFront 在列表前面插入
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. They must not be nil. PushBackList 在链表头部插入另一个链表的拷贝