linkedlist

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package linkedlist provides an interface and implementations for the linked list data structure

Index

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

func NewDLL[T any](items ...T) *DLL[T]

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]) Get

func (d *DLL[T]) Get(index int) (T, bool)

func (*DLL[T]) Insert

func (l *DLL[T]) Insert(index int, item T) bool

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 (q *DLL[T]) InsertNodeFront(insertedNode *DLLNode[T])

func (*DLL[T]) Map

func (d *DLL[T]) Map(f func(T) T) LinkedList[T]

func (*DLL[T]) PeekFront

func (q *DLL[T]) PeekFront() (T, bool)

func (*DLL[T]) PeekLast

func (q *DLL[T]) PeekLast() (T, bool)

func (*DLL[T]) Remove

func (l *DLL[T]) Remove(index int) bool

func (*DLL[T]) RemoveFront

func (q *DLL[T]) RemoveFront() (T, bool)

RemoveFront removes and returns the item at the front of the doubly-linked list.

func (*DLL[T]) RemoveLast

func (l *DLL[T]) RemoveLast() (T, bool)

RemoveLast removes and returns the item at the end of the doubly-linked list.

func (*DLL[T]) RemoveNode

func (l *DLL[T]) RemoveNode(ptr *DLLNode[T])

func (*DLL[T]) Size

func (q *DLL[T]) Size() int

Size returns the number of items in the list.

type DLLNode

type DLLNode[T any] struct {
	Val  T
	Prev *DLLNode[T]
	Next *DLLNode[T]
}

DoublyLinkedListNode is a data structure that contains a value and pointers to the previous and next nodes in the list.

func NewDLLNode

func NewDLLNode[T any](i T) *DLLNode[T]

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

func NewSLL[T any](items ...T) *SLL[T]

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]) Get

func (l *SLL[T]) Get(index int) (T, bool)

Get returns the item at a given index of the list.

func (*SLL[T]) Insert

func (l *SLL[T]) Insert(index int, item T) bool

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]) PeekFront

func (l *SLL[T]) PeekFront() (T, bool)

PeekFront returns the item at the front of the list.

func (*SLL[T]) PeekLast

func (l *SLL[T]) PeekLast() (T, bool)

PeekLast returns the item at the end of the list.

func (*SLL[T]) Remove

func (l *SLL[T]) Remove(index int) bool

func (*SLL[T]) RemoveFront

func (l *SLL[T]) RemoveFront() (T, bool)

RemoveFront removes and returns the item at the front of the singly-linked list.

func (*SLL[T]) RemoveLast

func (l *SLL[T]) RemoveLast() (T, bool)

RemoveLast removes and returns the item at the end of the list.

func (*SLL[T]) Size

func (l *SLL[T]) Size() int

Size returns the number of items in the list.

type SLLNode

type SLLNode[T any] struct {
	Val  T
	Next *SLLNode[T]
}

SinglyLinkedListNode is a data structure that contains a value and a pointer to the next node in the list.

func NewSLLNode

func NewSLLNode[T any](i T) *SLLNode[T]

NewSinglyLinkedListNode instantiates a singly-linked list node and returns a pointer to it.

Jump to

Keyboard shortcuts

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