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 (*Stack[T]) Peek ¶
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 ¶
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 ¶
Push adds the given item to the top of the stack; the stack is returned; never nil.
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.