datastructure

package
v2.3.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package datastructure contains some data structure. Link structure contains SinglyLink and DoublyLink.

Package datastructure contains some data structure. Link structure contains SinglyLink and DoublyLink.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DoublyLink[T any] struct {
	Head *datastructure.LinkNode[T]
	// contains filtered or unexported fields
}

DoublyLink is a linked list. Whose node has a generic Value, Pre pointer points to a previous node of the dl, Next pointer points to a next node of the dl.

func NewDoublyLink[T any]() *DoublyLink[T]

NewDoublyLink return *DoublyLink instance

func (*DoublyLink[T]) Clear

func (dl *DoublyLink[T]) Clear()

Clear all nodes in doubly linklist

func (*DoublyLink[T]) DeleteAt

func (dl *DoublyLink[T]) DeleteAt(index int)

DeleteAt delete value in doubly linklist at index param `index` should be [0, len(DoublyLink)-1]

func (*DoublyLink[T]) DeleteAtHead

func (dl *DoublyLink[T]) DeleteAtHead()

DeleteAtHead delete value in doubly linklist at head index

func (*DoublyLink[T]) DeleteAtTail

func (dl *DoublyLink[T]) DeleteAtTail()

DeleteAtTail delete value in doubly linklist at tail

func (*DoublyLink[T]) GetMiddleNode

func (dl *DoublyLink[T]) GetMiddleNode() *datastructure.LinkNode[T]

GetMiddleNode return node at middle index of linked list

func (*DoublyLink[T]) InsertAt

func (dl *DoublyLink[T]) InsertAt(index int, value T)

InsertAt insert value into doubly linklist at index param `index` should between [0, length], if index do not meet the conditions, do nothing

func (*DoublyLink[T]) InsertAtHead

func (dl *DoublyLink[T]) InsertAtHead(value T)

InsertAtHead insert value into doubly linklist at head index

func (*DoublyLink[T]) InsertAtTail

func (dl *DoublyLink[T]) InsertAtTail(value T)

InsertAtTail insert value into doubly linklist at tail index

func (*DoublyLink[T]) IsEmpty

func (dl *DoublyLink[T]) IsEmpty() bool

IsEmpty checks if dl is empty or not

func (*DoublyLink[T]) Print

func (dl *DoublyLink[T]) Print()

Print all nodes info of a linked list

func (*DoublyLink[T]) Reverse

func (dl *DoublyLink[T]) Reverse()

Reverse the linked list

func (*DoublyLink[T]) Size

func (dl *DoublyLink[T]) Size() int

Size return the count of doubly linked list

func (*DoublyLink[T]) Values

func (dl *DoublyLink[T]) Values() []T

Values return slice of all doubly linklist node value

type SinglyLink[T any] struct {
	Head *datastructure.LinkNode[T]
	// contains filtered or unexported fields
}

SinglyLink is a linked list. Whose node has a Value generics and Next pointer points to a next node of the sl.

func NewSinglyLink[T any]() *SinglyLink[T]

NewSinglyLink return *SinglyLink instance

func (*SinglyLink[T]) Clear

func (sl *SinglyLink[T]) Clear()

Clear all the node in singly linklist

func (*SinglyLink[T]) DeleteAt

func (sl *SinglyLink[T]) DeleteAt(index int)

DeleteAt delete value in singly linklist at index param `index` should be [0, len(SinglyLink)-1]

func (*SinglyLink[T]) DeleteAtHead

func (sl *SinglyLink[T]) DeleteAtHead()

DeleteAtHead delete value in singly linklist at head index

func (*SinglyLink[T]) DeleteAtTail

func (sl *SinglyLink[T]) DeleteAtTail()

DeleteAtTail delete value in singly linklist at tail

func (*SinglyLink[T]) DeleteValue added in v2.0.2

func (sl *SinglyLink[T]) DeleteValue(value T)

DeleteValue delete value in singly linklist

func (*SinglyLink[T]) GetMiddleNode

func (sl *SinglyLink[T]) GetMiddleNode() *datastructure.LinkNode[T]

GetMiddleNode return node at middle index of linked list

func (*SinglyLink[T]) InsertAt

func (sl *SinglyLink[T]) InsertAt(index int, value T)

InsertAt insert value into singly linklist at index param `index` should between [0, len(SinglyLink)], if index do not meet the conditions, do nothing

func (*SinglyLink[T]) InsertAtHead

func (sl *SinglyLink[T]) InsertAtHead(value T)

InsertAtHead insert value into singly linklist at head index

func (*SinglyLink[T]) InsertAtTail

func (sl *SinglyLink[T]) InsertAtTail(value T)

InsertAtTail insert value into singly linklist at tail index

func (*SinglyLink[T]) IsEmpty

func (sl *SinglyLink[T]) IsEmpty() bool

IsEmpty checks if sl is empty or not

func (*SinglyLink[T]) Print

func (sl *SinglyLink[T]) Print()

Print all nodes info of a linked list

func (*SinglyLink[T]) Reverse

func (sl *SinglyLink[T]) Reverse()

Reverse the linked list

func (*SinglyLink[T]) Size

func (sl *SinglyLink[T]) Size() int

Size return the count of singly linked list

func (*SinglyLink[T]) Values

func (sl *SinglyLink[T]) Values() []T

Values return slice of all singly linklist node value

Jump to

Keyboard shortcuts

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