stacks

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStackUnderflow = errors.New("stack underflow")

ErrStackUnderflow is returned when attempting to Pop from an empty Stack.

Functions

This section is empty.

Types

type Stack

type Stack[T comparable] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Stack is an abstract data type that serves as a collection of elements.

func NewStack

func NewStack[T comparable]() Stack[T]

NewStack creates and returns an initialized stack.

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() T

Peek returns the top element on the Stack, without removing it.

If the Stack is empty, nil is returned.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (T, error)

Pop pops the top element off the stack, it can return an error if the Stack is empty.

func (*Stack[T]) Push

func (s *Stack[T]) Push(e T)

Push pushes a new element onto the top of the Stack.

Jump to

Keyboard shortcuts

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