Documentation
¶
Overview ¶
Package stack provides a generic LIFO stack backed by a slice.
NOT safe for concurrent use. Callers must synchronize access externally.
Index ¶
- type Stack
- func (stack *Stack[T]) Clear()
- func (stack *Stack[T]) Copy() *Stack[T]
- func (stack *Stack[T]) IsEmpty() bool
- func (stack *Stack[T]) Len() int
- func (stack *Stack[T]) Peek() T
- func (stack *Stack[T]) Pop() T
- func (stack *Stack[T]) PopLeft() T
- func (stack *Stack[T]) Push(value T)
- func (stack *Stack[T]) PushLeft(value T)
- func (stack *Stack[T]) Reverse() *Stack[T]
- func (stack *Stack[T]) Set(values []T)
- func (stack *Stack[T]) ToSlice() []T
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 is a generic LIFO stack backed by a slice.
func (*Stack[T]) Copy ¶
Copy returns a deep copy of the stack. The new stack has independent storage but shares the same value references.
func (*Stack[T]) Peek ¶
func (stack *Stack[T]) Peek() T
Peek returns the top element without removing it. If the stack is empty, it returns the zero value.
func (*Stack[T]) Pop ¶
func (stack *Stack[T]) Pop() T
Pop removes and returns the top element. If the stack is empty, it returns the zero value.
func (*Stack[T]) PopLeft ¶
func (stack *Stack[T]) PopLeft() T
PopLeft removes and returns the bottom element. If the stack is empty, it returns the zero value.
func (*Stack[T]) Push ¶
func (stack *Stack[T]) Push(value T)
Push adds a value to the top of the stack.
func (*Stack[T]) PushLeft ¶
func (stack *Stack[T]) PushLeft(value T)
PushLeft adds a value to the bottom of the stack.