Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/jxskiss/gopkg/v2/collection/listx" ) func main() { // Create a new list and put some numbers in it. l := listx.NewList[int]() 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[T]) Back() *Element
- func (l *List[T]) Front() *Element
- func (l *List[T]) InsertAfter(v T, mark *Element) *Element
- func (l *List[T]) InsertBefore(v T, mark *Element) *Element
- func (l *List[T]) Len() int
- func (l *List[T]) MoveAfter(e, mark *Element)
- func (l *List[T]) MoveBefore(e, mark *Element)
- func (l *List[T]) MoveToBack(e *Element)
- func (l *List[T]) MoveToFront(e *Element)
- func (l *List[T]) PushBack(v T) *Element
- func (l *List[T]) PushBackList(other *List[T])
- func (l *List[T]) PushFront(v T) *Element
- func (l *List[T]) PushFrontList(other *List[T])
- func (l *List[T]) Remove(e *Element) T
- type Queue
- type Stack
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
List represents a doubly linked list. The zero value for List is an empty list ready to use.
func (*List[T]) 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.
func (*List[T]) 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.
func (*List[T]) 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.
func (*List[T]) 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.
func (*List[T]) 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.
func (*List[T]) 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.
func (*List[T]) PushBack ¶
PushBack inserts a new element e with value v at the back of list l and returns e.
func (*List[T]) 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.
func (*List[T]) PushFront ¶
PushFront inserts a new element e with value v at the front of list l and returns e.
func (*List[T]) 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.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a First In First Out data structure implementation. The zero value for Queue is an empty queue ready to use. A Queue is not safe for concurrent operations.
func (*Queue[T]) Dequeue ¶
Dequeue removes and returns the Queue's front item in *O(1)* time complexity.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack implements a Last In First Out data structure built upon a doubly-linked list. The zero value for Stack is an empty stack ready to use. A Stack is not safe for concurrent operations.
In most cases, a simple slice based implementation is a better choice.
func (*Stack[T]) Peek ¶
Peek returns the item on the top of the Stack in *O(1)* time complexity, it does not remove the item from the Stack.