deque

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 1 Imported by: 0

README

deque

Library of generic deque data structure for Go.

Install

$ go get github.com/golang-ds/deque

Deque Usage

Import
import "github.com/golang-ds/deque"
Use
d := deque.New[int]()
d.AddFirst(1)

Documentation

Overview

Package deque implements a generic deque using a doubly-linked-list as the underlying data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deque

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

func New

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

New constructs and returns an empty deque. time-complexity: O(1)

func (*Deque[T]) AddFirst

func (d *Deque[T]) AddFirst(data T)

AddFirst adds an element to the front of the deque. time-complexity: O(1)

func (*Deque[T]) AddLast

func (d *Deque[T]) AddLast(data T)

AddLast adds an element to the end of the deque. time-complexity: O(1)

func (*Deque[T]) First

func (d *Deque[T]) First() (T, bool)

First returns the first element in the deque. It returns false if the deque is empty. time-complexity: O(1)

func (*Deque[T]) IsEmpty

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

IsEmpty returns true if the deque doesn't have any elements. time-complexity: O(1)

func (*Deque[T]) Last

func (d *Deque[T]) Last() (T, bool)

Last returns the last element in the deque. It returns false if the deque is empty. time-complexity: O(1)

func (*Deque[T]) RemoveFirst

func (d *Deque[T]) RemoveFirst() (T, bool)

RemoveFirst removes the first element from the deque and returns it. It returns false if the deque is empty. time-complexity: O(1)

func (*Deque[T]) RemoveLast

func (d *Deque[T]) RemoveLast() (T, bool)

RemoveLast removes the last element from the deque and returns it. It returns false if the deque is empty. time-complexity: O(1)

func (*Deque[T]) Size

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

Size returns the number of the elements in the deque. time-complexity: O(1)

func (*Deque[T]) String

func (d *Deque[T]) String() string

String returns the string representation of the deque. time-complexity: O(n)

Jump to

Keyboard shortcuts

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