Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stack ¶
type Stack[E any] []E
Stack is a LIFO data structure. It is not thread-safe. It's backed by a slice, sot it can be used with `slices` package.
To preallocate a stack, use `make`:
st := make(stack.Stack[int], 0, 10)
func (*Stack[E]) Peek ¶
Peek returns the top element from the stack without removing it. If the stack is empty, the returned element is the zero value of the element type and the second return value is false.
func (*Stack[E]) PeekMany ¶
PeekMany appends the top n elements from the stack to the given slice without removing them. If the stack is empty, the returned slice is the same as the given slice.
func (*Stack[E]) Pop ¶
Pop removes and returns the top element from the stack. If the stack is empty, the returned element is the zero value of the element type and the second return value is false.
func (*Stack[E]) PopMany ¶
PopMany removes and appends the top n elements from the stack to the given slice. If the stack is empty, the returned slice is the same as the given slice. If the stack has less than n elements, all elements are removed.
Elements are appended to the given slice in the reverse order.
stack{1, 2, 3}.PopMany(nil, 2) => []int{3, 2}, stack{1}