stack

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 2 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 {
	// contains filtered or unexported fields
}

func NewStack

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

NewStack creates a new stack with passing `capacity` argument to `make(T[],...)`.

func NewStackWithCap

func NewStackWithCap[T any](capacity int) Stack[T]

NewStack creates a new stack with passing `capacity` argument to `make(T[],...)`.

func (*Stack[T]) Len

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

Len returns the length of the stack.

func (*Stack[T]) Pop

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

Pop pops the top element on the stack. The stack size needs to be greater > 0.

func (*Stack[T]) PopFront

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

PopFront pops the bottom level on the stack. This method is useful to do Breath-First-Traversal. instead of Depth-First-Traversal when using `Pop`.

func (*Stack[T]) Push

func (s *Stack[T]) Push(t ...T)

Push appends an element to the stack.

func (*Stack[T]) Visit

func (s *Stack[T]) Visit(visitor func(int, T) bool)

Visit travers the stack from top to bottom and applies a function. If the visitor returns `false` the iteration is aborted.

func (*Stack[T]) VisitUpward

func (s *Stack[T]) VisitUpward(visitor func(int, T) bool)

Visit travers the stack from bottom to top and applies a function. If the visitor returns `false` the iteration is aborted.

Jump to

Keyboard shortcuts

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