Documentation
¶
Overview ¶
doubly implements a generic doubly-linked-list library for Go.
Index ¶
- type LinkedList
- func (d *LinkedList[T]) AddBetween(data T, predecessor *Node[T], successor *Node[T])
- func (d *LinkedList[T]) AddFirst(data T)
- func (d *LinkedList[T]) AddLast(data T)
- func (d *LinkedList[T]) First() (data T, ok bool)
- func (d *LinkedList[T]) IsEmpty() bool
- func (d *LinkedList[T]) Last() (data T, ok bool)
- func (d *LinkedList[T]) Remove(n *Node[T]) T
- func (d *LinkedList[T]) RemoveFirst() (data T, ok bool)
- func (d *LinkedList[T]) RemoveLast() (data T, ok bool)
- func (d *LinkedList[T]) String() string
- func (d *LinkedList[T]) ToSlice() []T
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LinkedList ¶
func New ¶
func New[T any]() LinkedList[T]
New constructs and returns an empty doubly linked-list. time-complexity: O(1)
func (*LinkedList[T]) AddBetween ¶
func (d *LinkedList[T]) AddBetween(data T, predecessor *Node[T], successor *Node[T])
AddBetween constructs a new node out of the given data and inserts it between the given two nodes. time-complexity: O(1)
func (*LinkedList[T]) AddFirst ¶
func (d *LinkedList[T]) AddFirst(data T)
AddFirst adds a new node to the beginning of the list. time-complexity: O(1)
func (*LinkedList[T]) AddLast ¶
func (d *LinkedList[T]) AddLast(data T)
AddLast adds a new node to the end of the list. time-complexity: O(1)
func (*LinkedList[T]) First ¶
func (d *LinkedList[T]) First() (data T, ok bool)
First returns the first element of the list. It returns false if the list is empty. time-complexity: O(1)
func (*LinkedList[T]) IsEmpty ¶
func (d *LinkedList[T]) IsEmpty() bool
IsEmpty returns true if the linked-list doesn't contain any nodes. time-complexity: O(1)
func (*LinkedList[T]) Last ¶
func (d *LinkedList[T]) Last() (data T, ok bool)
Last returns the last element of the list. It returns false if the list is empty. time-complexity: O(1)
func (*LinkedList[T]) Remove ¶
func (d *LinkedList[T]) Remove(n *Node[T]) T
Remove removes the given node from the list. It returns the removed node's data. time-complexity: O(1)
func (*LinkedList[T]) RemoveFirst ¶
func (d *LinkedList[T]) RemoveFirst() (data T, ok bool)
RemoveFirst removes and returns the first element of the list. It returns false if the list is empty. time-complexity: O(1)
func (*LinkedList[T]) RemoveLast ¶
func (d *LinkedList[T]) RemoveLast() (data T, ok bool)
RemoveLast removes and returns the last element of the list. It returns false if the list empty. time-complexity: O(1)
func (*LinkedList[T]) String ¶
func (d *LinkedList[T]) String() string
String returns the string representation of the list. time-complexity: O(n)
func (*LinkedList[T]) ToSlice ¶
func (d *LinkedList[T]) ToSlice() []T
ToSlice returns the linked-list as a slice. time-complexity: O(n)