linkedlist

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNodeNotFound  = errors.New("node not found")
	ErrValueNotFound = errors.New("value not found")
)

Functions

func DisplayList

func DisplayList[T any](head *Node[T])

DisplayList prints the elements of the linked list

func SortLinkedList

func SortLinkedList[T any](ll *LinkedList[T], less func(i, j T) bool)

func SortLinkedListIterative

func SortLinkedListIterative[T any](ll *LinkedList[T], less func(i, j T) bool)

Types

type Compariable

type Compariable interface {
	Compare(interface{}) int
}

type LinkedList

type LinkedList[T any] struct {
	Head *Node[T]
	Tail *Node[T]
	// contains filtered or unexported fields
}

func New

func New[T any](items ...T) *LinkedList[T]

New returns a new linked list.

func (*LinkedList[T]) Contains

func (l *LinkedList[T]) Contains(value T) bool

Contains returns true if the linked list contains the given value.

func (*LinkedList[T]) Empty

func (l *LinkedList[T]) Empty() bool

Empty returns true if the linked list is empty.

func (*LinkedList[T]) Insert

func (l *LinkedList[T]) Insert(value T)

Insert inserts a new node at the end of the linked list.

func (*LinkedList[T]) InsertBefore

func (l *LinkedList[T]) InsertBefore(node *Node[T], value T) error

InsertBefore inserts a new node with the specififed value, before the given node.

func (*LinkedList[T]) Len

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

Len returns the length of the linked list.

func (*LinkedList[T]) Remove

func (l *LinkedList[T]) Remove(value T) error

Remove removes the given node from the linked list.

func (*LinkedList[T]) RemoveTail

func (l *LinkedList[T]) RemoveTail() error

RemoveTail removes the last node from the linked list.

func (*LinkedList[T]) String

func (l *LinkedList[T]) String() string

String returns a string representation of the linked list.

type Node

type Node[T any] struct {
	Value T
	Next  *Node[T]
}

Node represents a node in the linked list.

Jump to

Keyboard shortcuts

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