deque

package module
v0.0.0-...-654030a Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package deque represents deque abstract data structure and basic operations on it. Deque is similar to queue, but elements can be inserted and removed from the start and from the end.

Actually deque is the generalized structure of all types of queues.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deque

type Deque[T any] []T

Deque represents the deque structure.

func New

func New[T any]() *Deque[T]

New creates new deque instance and returns pointer to it.

func (*Deque[T]) Back

func (d *Deque[T]) Back() T

Back returns the back (last) element of the deque.

func (*Deque[T]) Empty

func (d *Deque[T]) Empty() bool

Empty checks that deque is empty.

func (*Deque[T]) Front

func (d *Deque[T]) Front() T

Front returns the front (first) element of the deque.

func (*Deque[T]) Len

func (d *Deque[T]) Len() int

Len returns the size (length) of the deque

func (*Deque[T]) PopBack

func (d *Deque[T]) PopBack() T

PopBack pops out an element from the end of the deque and returns popped element. Before pop it is a good practice to check is deque is empty or not.

deque := deque.New[any]()
if !deque.Empty() {
	_ = deque.PopBack()
}

func (*Deque[T]) PopFront

func (d *Deque[T]) PopFront() T

PopFront pops out an element from the front of the deque and returns popped element. Before pop it is a good practice to check is deque is empty or not.

deque := deque.New[any]()
if !deque.Empty() {
	_ = deque.PopFront()
}

func (*Deque[T]) PushBack

func (d *Deque[T]) PushBack(v T) T

PushBack puts an element to the end of the deque and returns pushed element.

func (*Deque[T]) PushFront

func (d *Deque[T]) PushFront(v T) T

PushFront puts an element to the beginning of the deque and returns pushed element.

Jump to

Keyboard shortcuts

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