stack

package
v0.0.0-...-1a31a9c Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package stack implements a generic LIFO stack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stack

type Stack[E any] []E

Stack is a generic LIFO stack.

func New

func New[E any]() *Stack[E]

New creates a new stack.

func (*Stack[E]) Backward

func (s *Stack[E]) Backward() iter.Seq2[int, E]

Backward returns an iterator over index-value pairs in the stack, traversing it backward with descending indices.

func (*Stack[E]) Clear

func (s *Stack[E]) Clear()

Clear removes all elements from the stack.

func (*Stack[E]) Len

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

Len returns the number of elements in the stack.

func (*Stack[E]) Peek

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

Peek returns the top value of the stack without removing it. If the stack is empty, it panics.

func (*Stack[E]) Pop

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

Pop pops a value from the stack and returns it. If the stack is empty, it panics.

func (*Stack[E]) Push

func (s *Stack[E]) Push(v E)

Push pushes a value onto the stack.

func (*Stack[E]) String

func (s *Stack[E]) String() string

Jump to

Keyboard shortcuts

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