list
4 分钟阅读
Package list implements a doubly linked list.
list包实现了一个双链表(a doubly linked list.)。
To iterate over a list (where l is a *List):
迭代一个列表(其中l是一个*List):
| |
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,该列表不会被修改。e和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,该列表不会被修改。e和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。