doubly

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

doubly implements a generic doubly-linked-list library for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LinkedList

type LinkedList[T any] struct {
	Size int
	// contains filtered or unexported fields
}

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)

type Node

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

func (*Node[T]) String

func (n *Node[T]) String() string

String returns the string representation of the node's data. time-complexity: O(1)

Jump to

Keyboard shortcuts

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