list

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package list implements a doubly linked list. See https://en.wikipedia.org/wiki/Linked_list for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List represents a doubly linked list. Zero value of List is empty list.

func New

func New[T any]() *List[T]

New returns an initialized list.

func (*List[T]) All

func (l *List[T]) All() []T

All returns all elements from the list.

func (*List[T]) Back

func (l *List[T]) Back() T

Back returns last element.

func (*List[T]) ChangeAt

func (l *List[T]) ChangeAt(i int, value T)

ChangeAt changes value at given index. Returns zero value if list is empty.

func (*List[T]) Clear

func (l *List[T]) Clear()

Clear clears list.

func (*List[T]) Cut

func (l *List[T]) Cut(i int) (*List[T], *List[T])

Cut cuts list into two list. i is last element in first list, for example cut(1) for list {1,2,3,4,5} returns {1,2}, {3,4,5}.

func (*List[T]) Front

func (l *List[T]) Front() T

Front returns first element.

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(node *Node[T], value T)

InsertAfter adds new Node with given value after given Node.

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(n *Node[T], value T)

InsertBefore adds new Node with given value before given Node.

func (*List[T]) Len

func (l *List[T]) Len() int

Len returns length of the list.

func (*List[T]) Merge

func (l *List[T]) Merge(other *List[T])

Merge merges two lists.

func (*List[T]) Node

func (l *List[T]) Node(i int) *Node[T]

Node returns Node at the given index. Returns zero value if index is less or equal to len of the list.

func (*List[T]) Peek

func (l *List[T]) Peek(i int) T

Peek returns element at the given index. Returns zero value if index is less or equal to len of the list.

func (*List[T]) PopBack

func (l *List[T]) PopBack() T

PopBack removes last element of the list. Returns zero value if list is empty.

func (*List[T]) PopFront

func (l *List[T]) PopFront() T

PopFront removes first element of the list. Returns zero value if list is empty.

func (*List[T]) PushBack

func (l *List[T]) PushBack(value T)

PushBack adds value to the end of the list.

func (*List[T]) PushFront

func (l *List[T]) PushFront(value T)

PushFront adds value to the beginning of the list.

func (*List[T]) Remove

func (l *List[T]) Remove(n *Node[T])

Remove removes given node from list.

func (*List[T]) Reverse

func (l *List[T]) Reverse()

Reverse reverses list.

type Node

type Node[T any] struct {
	Value T
	// contains filtered or unexported fields
}

Node represents node of a list.

func (*Node[T]) HasNext

func (n *Node[T]) HasNext() bool

HasNext return true if next node exists.

func (*Node[T]) HasPrev

func (n *Node[T]) HasPrev() bool

HasPrev return true if previous node exists.

func (*Node[T]) Next

func (n *Node[T]) Next() *Node[T]

Next returns next Node.

func (*Node[T]) Prev

func (n *Node[T]) Prev() *Node[T]

Prev returns previous Node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL