stackarr

package
v0.0.0-...-56b3168 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

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

func NewStack

func NewStack[T any](size int) *Stack[T]

Stack constructor

func (*Stack[T]) ExtractMany

func (stack *Stack[T]) ExtractMany(amountToExtract int) (items []T, err error)

Extract many items from the stack in a new slice

args: amount of items to extract

returns: slice of the items extracted for example, if the stack is [1, 2, 3], and you request 2, the result would be [2, 3]

the method returns an error if you request to extract more items than available

func (*Stack[T]) InsertFromSlice

func (stack *Stack[T]) InsertFromSlice(items []T)

Insert many items from a slice to the stack For example, if the stack is [1] and the slice is [2, 3], the stack will be [1, 2, 3]

func (*Stack[T]) Len

func (stack *Stack[T]) Len() int

Get the current length of the stack

func (*Stack[T]) PeekNext

func (stack *Stack[T]) PeekNext() (nextItem T, err error)

Returns the value of the next item without removing it from the stack returns an error if the stack is empty

func (*Stack[T]) Pop

func (stack *Stack[T]) Pop() (nextItem T, err error)

Remove next item of the stack and return its value Returns an error if the stack is empty

func (*Stack[T]) Push

func (stack *Stack[T]) Push(item T) bool

Add a new item into the stack

func (Stack[T]) String

func (stack Stack[T]) String() string

Prints Stack in format "Stack[T][item1 itemn]"

Jump to

Keyboard shortcuts

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