stack

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 0 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] []T

Stack is the default, private implementation of a Stack.

func New

func New[T any](cap ...int) *Stack[T]

New creates a new stack with an optional initial capacity.

func (*Stack[T]) Cap

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

Cap returns the capacity of the stack.

func (*Stack[T]) Len

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

Len returns the number of elements in the stack.

func (*Stack[T]) Peek

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

Peek returns the top element of the stack without removing it.

func (*Stack[T]) Pop

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

Pop removes and returns the top element of the stack. If the stack is empty, it returns the zero value of type T and false. Otherwise, it returns the top element and true.

func (*Stack[T]) Push

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

Push adds an 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