datastructure

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package datastructure contains some data structure. Queue structure contains ArrayQueue, LinkedQueue, CircularQueue, and PriorityQueue.

Package datastructure contains some data structure. Queue structure contains ArrayQueue, LinkedQueue, CircularQueue, and PriorityQueue.

Package datastructure contains some data structure. Queue structure contains ArrayQueue, LinkedQueue, CircularQueue, and PriorityQueue.

Package datastructure contains some data structure. Queue structure contains ArrayQueue, LinkedQueue, CircularQueue, and PriorityQueue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayQueue

type ArrayQueue[T any] struct {
	// contains filtered or unexported fields
}

ArrayQueue implements queue with slice

func NewArrayQueue

func NewArrayQueue[T any](capacity int) *ArrayQueue[T]

func (*ArrayQueue[T]) Back

func (q *ArrayQueue[T]) Back() T

Back return back value of queue

func (*ArrayQueue[T]) Clear

func (q *ArrayQueue[T]) Clear()

Clear the queue data

func (*ArrayQueue[T]) Contain

func (q *ArrayQueue[T]) Contain(value T) bool

Contain checks if the value is in queue or not

func (*ArrayQueue[T]) Data

func (q *ArrayQueue[T]) Data() []T

Data return slice of queue data

func (*ArrayQueue[T]) Dequeue added in v2.0.4

func (q *ArrayQueue[T]) Dequeue() (T, bool)

DeQueue remove head element of queue and return it, if queue is empty, return nil and error

func (*ArrayQueue[T]) Enqueue added in v2.0.4

func (q *ArrayQueue[T]) Enqueue(item T) bool

EnQueue put element into queue

func (*ArrayQueue[T]) Front

func (q *ArrayQueue[T]) Front() T

Front return front value of queue

func (*ArrayQueue[T]) IsEmpty

func (q *ArrayQueue[T]) IsEmpty() bool

IsEmpty checks if queue is empty or not

func (*ArrayQueue[T]) IsFull added in v2.0.8

func (q *ArrayQueue[T]) IsFull() bool

IsFull checks if queue is full or not

func (*ArrayQueue[T]) Print

func (q *ArrayQueue[T]) Print()

Print queue data

func (*ArrayQueue[T]) Size

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

Size return number of elements in queue

type CircularQueue

type CircularQueue[T any] struct {
	// contains filtered or unexported fields
}

CircularQueue implements circular queue with slice, last index of CircularQueue don't contain value, so acturl capacity is capacity - 1

func NewCircularQueue

func NewCircularQueue[T any](capacity int) *CircularQueue[T]

NewCircularQueue return a empty CircularQueue pointer

func (*CircularQueue[T]) Back

func (q *CircularQueue[T]) Back() T

Back return back value of queue

func (*CircularQueue[T]) Clear

func (q *CircularQueue[T]) Clear()

Clear the queue data

func (*CircularQueue[T]) Contain

func (q *CircularQueue[T]) Contain(value T) bool

Contain checks if the value is in queue or not

func (*CircularQueue[T]) Data

func (q *CircularQueue[T]) Data() []T

Data return slice of queue data

func (*CircularQueue[T]) Dequeue added in v2.0.8

func (q *CircularQueue[T]) Dequeue() (*T, error)

Dequeue remove head element of queue and return it, if queue is empty, return nil and error

func (*CircularQueue[T]) Enqueue added in v2.0.8

func (q *CircularQueue[T]) Enqueue(value T) error

Enqueue put element into queue

func (*CircularQueue[T]) Front

func (q *CircularQueue[T]) Front() T

Front return front value of queue

func (*CircularQueue[T]) IsEmpty

func (q *CircularQueue[T]) IsEmpty() bool

IsEmpty checks if queue is empty or not

func (*CircularQueue[T]) IsFull

func (q *CircularQueue[T]) IsFull() bool

IsFull checks if queue is full or not

func (*CircularQueue[T]) Print

func (q *CircularQueue[T]) Print()

Print queue data

func (*CircularQueue[T]) Size added in v2.0.8

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

Size return number of elements in circular queue

type LinkedQueue

type LinkedQueue[T any] struct {
	// contains filtered or unexported fields
}

LinkedQueue implements queue with link list

func NewLinkedQueue

func NewLinkedQueue[T any]() *LinkedQueue[T]

NewLinkedQueue return a empty LinkedQueue pointer

func (*LinkedQueue[T]) Back

func (q *LinkedQueue[T]) Back() (*T, error)

Back return back value of queue

func (*LinkedQueue[T]) Clear

func (q *LinkedQueue[T]) Clear()

Clear clear the queue data

func (*LinkedQueue[T]) Contain added in v2.0.8

func (q *LinkedQueue[T]) Contain(value T) bool

Contain checks if the value is in queue or not

func (*LinkedQueue[T]) Data

func (q *LinkedQueue[T]) Data() []T

Data return slice of queue data

func (*LinkedQueue[T]) Dequeue added in v2.0.8

func (q *LinkedQueue[T]) Dequeue() (*T, error)

Dequeue delete head element of queue then return it, if queue is empty, return nil and error

func (*LinkedQueue[T]) Enqueue added in v2.0.8

func (q *LinkedQueue[T]) Enqueue(value T)

Enqueue put element into queue

func (*LinkedQueue[T]) Front

func (q *LinkedQueue[T]) Front() (*T, error)

Front return front value of queue

func (*LinkedQueue[T]) IsEmpty

func (q *LinkedQueue[T]) IsEmpty() bool

IsEmpty checks if queue is empty or not

func (*LinkedQueue[T]) Print

func (q *LinkedQueue[T]) Print()

Print all nodes info of queue link

func (*LinkedQueue[T]) Size

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

Size return length of queue data

type PriorityQueue added in v2.0.6

type PriorityQueue[T any] struct {
	// contains filtered or unexported fields
}

PriorityQueue is a priority queue implemented by binary heap tree type T should implements Compare function in lancetconstraints.Comparator interface.

func NewPriorityQueue added in v2.0.6

func NewPriorityQueue[T any](capacity int, comparator lancetconstraints.Comparator) *PriorityQueue[T]

NewPriorityQueue return a pointer of PriorityQueue param `comparator` is used to compare values in the queue

func (*PriorityQueue[T]) Data added in v2.0.6

func (q *PriorityQueue[T]) Data() []T

Data return a slice of queue data

func (*PriorityQueue[T]) Dequeue added in v2.0.6

func (q *PriorityQueue[T]) Dequeue() (T, bool)

Dequeue delete and return max value in queue

func (*PriorityQueue[T]) Enqueue added in v2.0.6

func (q *PriorityQueue[T]) Enqueue(val T) error

Enqueue insert value into queue

func (*PriorityQueue[T]) IsEmpty added in v2.0.6

func (q *PriorityQueue[T]) IsEmpty() bool

IsEmpty checks if the queue is empty or not

func (*PriorityQueue[T]) IsFull added in v2.0.6

func (q *PriorityQueue[T]) IsFull() bool

IsFull checks if the queue capacity is full or not

func (*PriorityQueue[T]) Size added in v2.0.8

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

Size get number of items in the queue

Jump to

Keyboard shortcuts

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