Documentation ¶
Overview ¶
Package linkedlist provides an interface and implementations for the linked list data structure
Index ¶
- type DLL
- func (d *DLL[T]) Equal(f LinkedList[T]) bool
- func (d *DLL[T]) Filter(f func(T) bool) LinkedList[T]
- func (d *DLL[T]) Get(index int) (T, bool)
- func (l *DLL[T]) Insert(index int, item T) bool
- func (q *DLL[T]) InsertFront(i T)
- func (q *DLL[T]) InsertLast(i T)
- func (q *DLL[T]) InsertNodeFront(insertedNode *DLLNode[T])
- func (d *DLL[T]) Map(f func(T) T) LinkedList[T]
- func (q *DLL[T]) PeekFront() (T, bool)
- func (q *DLL[T]) PeekLast() (T, bool)
- func (l *DLL[T]) Remove(index int) bool
- func (q *DLL[T]) RemoveFront() (T, bool)
- func (l *DLL[T]) RemoveLast() (T, bool)
- func (l *DLL[T]) RemoveNode(ptr *DLLNode[T])
- func (q *DLL[T]) Size() int
- type DLLNode
- type LinkedList
- type SLL
- func (l *SLL[T]) Equal(m LinkedList[T]) bool
- func (l *SLL[T]) Filter(f func(T) bool) LinkedList[T]
- func (l *SLL[T]) Get(index int) (T, bool)
- func (l *SLL[T]) Insert(index int, item T) bool
- func (l *SLL[T]) InsertFront(i T)
- func (l *SLL[T]) InsertLast(i T)
- func (l *SLL[T]) Map(f func(T) T) LinkedList[T]
- func (l *SLL[T]) PeekFront() (T, bool)
- func (l *SLL[T]) PeekLast() (T, bool)
- func (l *SLL[T]) Remove(index int) bool
- func (l *SLL[T]) RemoveFront() (T, bool)
- func (l *SLL[T]) RemoveLast() (T, bool)
- func (l *SLL[T]) Size() int
- type SLLNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DLL ¶
type DLL[T any] struct { // contains filtered or unexported fields }
Double-ended queue enables inserting and polling from either end
func NewDLL ¶
NewDoublyLinkedList instantiates a new doubly-linked list and returns a pointer to it.
func (*DLL[T]) Equal ¶
func (d *DLL[T]) Equal(f LinkedList[T]) bool
func (*DLL[T]) Filter ¶
func (d *DLL[T]) Filter(f func(T) bool) LinkedList[T]
func (*DLL[T]) Insert ¶
Insert inserts a new item at the given index of the list. It returns a Boolean if the index is true if the index was within the bounds of the list and it was possible to insert the item.
func (*DLL[T]) InsertFront ¶
func (q *DLL[T]) InsertFront(i T)
InsertFront inserts a new item at the front of the list.
func (*DLL[T]) InsertLast ¶
func (q *DLL[T]) InsertLast(i T)
InsertLast inserts a new item at the end of the list.
func (*DLL[T]) InsertNodeFront ¶
func (*DLL[T]) Map ¶
func (d *DLL[T]) Map(f func(T) T) LinkedList[T]
func (*DLL[T]) RemoveFront ¶
RemoveFront removes and returns the item at the front of the doubly-linked list.
func (*DLL[T]) RemoveLast ¶
RemoveLast removes and returns the item at the end of the doubly-linked list.
func (*DLL[T]) RemoveNode ¶
type DLLNode ¶
DoublyLinkedListNode is a data structure that contains a value and pointers to the previous and next nodes in the list.
func NewDLLNode ¶
NewDoublyLinkedListNode instantiates a doubly-linked list node and returns a pointer to it.
type LinkedList ¶
type LinkedList[T any] interface { Size() int InsertFront(i T) InsertLast(i T) Insert(int, T) bool RemoveFront() (T, bool) RemoveLast() (T, bool) PeekFront() (T, bool) PeekLast() (T, bool) Get(int) (T, bool) Remove(int) bool Equal(LinkedList[T]) bool Map(func(T) T) LinkedList[T] Filter(func(T) bool) LinkedList[T] }
type SLL ¶
type SLL[T any] struct { // contains filtered or unexported fields }
func NewSLL ¶
NewSinglyLinkedList instantiates a new singly-linked list and returns a pointer to it.
func (*SLL[T]) Equal ¶
func (l *SLL[T]) Equal(m LinkedList[T]) bool
func (*SLL[T]) Filter ¶
func (l *SLL[T]) Filter(f func(T) bool) LinkedList[T]
Filter applies a given predicate function to each item in the list and returns a linked list of all items for which the predicate is true.
func (*SLL[T]) Insert ¶
Insert inserts a new item at the given index of the list. It returns a Boolean if the index is true if the index was within the bounds of the list and it was possible to insert the item.
func (*SLL[T]) InsertFront ¶
func (l *SLL[T]) InsertFront(i T)
InsertFront inserts a new item at the front of the list.
func (*SLL[T]) InsertLast ¶
func (l *SLL[T]) InsertLast(i T)
InsertLast inserts a new item at the end of the list.
func (*SLL[T]) Map ¶
func (l *SLL[T]) Map(f func(T) T) LinkedList[T]
Map applies a given function to each item in the list.
func (*SLL[T]) RemoveFront ¶
RemoveFront removes and returns the item at the front of the singly-linked list.
func (*SLL[T]) RemoveLast ¶
RemoveLast removes and returns the item at the end of the list.
type SLLNode ¶
SinglyLinkedListNode is a data structure that contains a value and a pointer to the next node in the list.
func NewSLLNode ¶
NewSinglyLinkedListNode instantiates a singly-linked list node and returns a pointer to it.