stack

package
v0.0.0-...-1605a13 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

ErrEmpty represents the error when trying to pop from an empty stack.

Functions

This section is empty.

Types

type Stack

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

Stack is a generic stack data structure that can store any type of value.

func New

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

New creates and returns a new stack with the specified capacity.

func (*Stack[T]) Clear

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

Clear removes all elements from the stack, effectively resetting it.

func (*Stack[T]) IsEmpty

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

IsEmpty checks if the stack is empty and returns a boolean result.

func (*Stack[T]) Peek

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

Peek returns the top element of the stack without removing it. If the stack is empty, it returns an error.

func (*Stack[T]) Pop

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

Pop removes and returns the top element of the stack. If the stack is empty, it returns an error.

func (*Stack[T]) Push

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

Push adds a new element to the top of the stack.

Jump to

Keyboard shortcuts

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