stack

package
v0.0.0-...-881dfb5 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty = errors.New("empty stack")
)

Functions

This section is empty.

Types

type Stack

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

Stack stores elements in a slice and offers First-In-First-Out access.

func NewStack

func NewStack[V any]() *Stack[V]

NewStack creates an empty stack.

func (*Stack[V]) IsEmpty

func (s *Stack[V]) IsEmpty() bool

IsEmpty returns true iff the stack is empty.

func (*Stack[V]) Pop

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

Pop removes the top of stack and returns it, if the stack is not empty. Returns ErrEmpty if the stack is empty.

func (*Stack[V]) Push

func (s *Stack[V]) Push(x V)

Push pushes a new element to the top of stack.

func (*Stack[V]) Size

func (s *Stack[V]) Size() int

Size returns the number of elements in the stack.

func (*Stack[V]) Top

func (s *Stack[V]) Top() (V, error)

Top returns the top of stack, if the stack is not empty. Returns ErrEmpty if the stack is empty.

Jump to

Keyboard shortcuts

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