stack

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stack defines a simple stack container.

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
}

Stack models a stack of values that can be pushed, peeked, and popped. This type is not thread-safe.

func New

func New[T any](size int) *Stack[T]

New creates a stack of the given size.

func (*Stack[T]) Peek

func (stack *Stack[T]) Peek() (item T, err error)

Peek returns the value of the item on the top of the stack; additionally, the zero value and an error is returned if the stack is empty.

func (*Stack[T]) Pop

func (stack *Stack[T]) Pop() (item T, err error)

Pop removes and returns the item on the top of the stack; additionally, the zero value and an error is returned if the stack is empty.

func (*Stack[T]) Push

func (stack *Stack[T]) Push(item T) *Stack[T]

Push adds the given item to the top of the stack; the stack is returned; never nil.

func (*Stack[T]) Size

func (stack *Stack[T]) Size() int

Size returns the size of the stack; never negative.

func (*Stack[T]) ToSlice

func (stack *Stack[T]) ToSlice() []T

ToSlice returns a slice containing the content of the stack. The first item in the slice is the top of the stack, and the last time in the slice is the bottom of the stack. Changes to the returned slice do not change the state of the stack. Returns an empty slice if the stack is empty; never nil.

Jump to

Keyboard shortcuts

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