linkedlist

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package linkedlist provides functionality for creating and manipulating doubly linked lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFirst

func AddFirst[T any](ll *LinkedList[T], n *Node[T])

AddFirst adds a node to the beginning of the linked list.

func AddLast

func AddLast[T any](ll *LinkedList[T], n *Node[T])

AddLast adds a node to the end of the linked list.

func Clear

func Clear[T any](ll *LinkedList[T])

Clear removes all elements from the linked list. Breaks all connections between nodes and sets the head and tail to nil.

func Contains

func Contains[T comparable](ll *LinkedList[T], e *T) bool

Contains returns true if the linked list contains the element as a value in a node.

func ContainsWith

func ContainsWith[T any](ll *LinkedList[T], e *T, p func(*T, *T) bool) bool

ContainsWith returns true if the linked list contains the element as a value in a node using the provided comparator.

func Insert

func Insert[T any](ll *LinkedList[T], index int, n *Node[T])

Insert inserts the element at the specified index. Index 0 is the head of the list.

func Remove

func Remove[T any](ll *LinkedList[T], index int)

Remove removes the element at the specified index. Index 0 is the head of the list.

func ToSlice

func ToSlice[T any](ll LinkedList[T]) (s []T)

ToSlice returns a slice from a linked list.

Types

type LinkedList

type LinkedList[T any] struct {
	Head   *Node[T]
	Tail   *Node[T]
	Length int
}

LinkedList is a doubly linked list.

func FromSlice

func FromSlice[T any](s []T) (ll LinkedList[T])

FromSlice returns a linked list from a slice/array.

type Node

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

Node is a node in a doubly linked list.

func Get

func Get[T any](ll *LinkedList[T], index int) *Node[T]

Get returns the node at the specified index.

Jump to

Keyboard shortcuts

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