Documentation ¶
Overview ¶
Package stack implements a generic stack data structure.
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 represents the stack data structure.
func New ¶
New returns an initialized stack, optionally with the given elements. The elements are pushed in the same order as provided.
func (*Stack[T]) Peek ¶
Peek returns the top element on the stack without removing it, or nil if the stack is empty.
An attempt to peek when the stack is empty will return the zero value for the type of the elements in the stack. Using multiple assignment, one can distinguish a missing entry from a zero value. This is referred to as the "comma ok" idiom.
func (*Stack[T]) Pop ¶
Pop removes the top element on the stack and returns it, or nil if the stack is empty.
An attempt to pop when the stack is empty will return the zero value for the type of the elements in the stack. Using multiple assignment, one can distinguish a missing entry from a zero value. This is referred to as the "comma ok" idiom.