list
4 分钟阅读
list
https://pkg.go.dev/container/list@go1.20.1
Package list implements a doubly linked list.
包list实现了一个双链表。
To iterate over a list (where l is a *List):
要在一个列表上进行迭代(其中l是一个*List):
for e := l.Front(); e != nil; e = e.Next() {
// do something with e.Value
//对e.Value做一些处理
}
Example
|
|
常量
This section is empty.
变量
This section is empty.
函数
This section is empty.
类型
type Element
|
|
Element is an element of a linked list.
Element是链接列表的一个元素。
(*Element) Next
|
|
Next returns the next list element or nil.
Next 返回下一个列表元素或nil。
(*Element) Prev
|
|
Prev returns the previous list element or nil.
Prev返回前一个列表元素或nil。
type List
|
|
List represents a doubly linked list. The zero value for List is an empty list ready to use.
List表示一个双链表。List的零值是一个准备使用的空列表。
func New
|
|
New returns an initialized list.
New返回一个初始化的列表。
(*List) Back
|
|
Back returns the last element of list l or nil if the list is empty.
Back返回列表l的最后一个元素,如果列表为空,则返回nil。
(*List) Front
|
|
Front returns the first element of list l or nil if the list is empty.
Front返回列表l的第一个元素,如果列表为空则返回nil。
(*List) Init
|
|
Init initializes or clears list l.
Init 初始化或清除列表l。
(*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.
InsertAfter在mark之后插入一个新的元素e,其值为v,并返回e。如果mark不是l的一个元素,列表不会被修改。mark不能是nil。
(*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在mark之前插入一个新的元素e,其值为v,并返回e,如果mark不是l的一个元素,列表就不会被修改。mark不能是nil。
(*List) Len
|
|
Len returns the number of elements of list l. The complexity is O(1).
Len返回列表l的元素数,其复杂度为O(1)。
(*List) MoveAfter <- go1.2
|
|
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.
MoveAfter将元素e移动到mark之后的新位置。如果e或mark不是l的一个元素,或者e == mark,列表不会被修改。元素和mark不能是nil。
(*List) MoveBefore <- go1.2
|
|
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.
MoveBefore将元素e移动到mark之前的新位置。如果e或mark不是l的一个元素,或者e == mark,列表不会被修改。元素和mark不能是nil。
(*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把元素e移到列表l的后面。如果e不是l的一个元素,列表不会被修改。该元素不能是nil。
(*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把元素e移到列表l的前面,如果e不是l的元素,列表不被修改。该元素不能是nil。
(*List) PushBack
|
|
PushBack inserts a new element e with value v at the back of list l and returns e.
PushBack在列表l的后面插入一个新元素e,其值为v,并返回e。
(*List) PushBackList
|
|
PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.
PushBackList在列表l的后面插入一个另一个列表的副本。它们不能是nil。
(*List) PushFront
|
|
PushFront inserts a new element e with value v at the front of list l and returns e.
PushFront在列表l的前面插入一个值为v的新元素e,并返回e。
(*List) PushFrontList
|
|
PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.
PushFrontList在列表l的前面插入一个另一个列表的副本。它们不能是nil。
(*List) Remove
|
|
Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.
如果e是列表l的一个元素,Remove将e从l中移除,并返回元素值e.Value。该元素不能是nil。