Documentation ¶
Overview ¶
Package stack provides an implementation of a LIFO stack built using a resizing array.
Example ¶
package main import ( "fmt" "github.com/fufuok/utils/generic/stack" ) func main() { st := stack.New[string]() st.Push("foo") st.Push("bar") fmt.Println(st.Pop()) fmt.Println(st.Peek()) st.Push("baz") fmt.Println(st.Size()) }
Output: bar foo 2
Index ¶
Examples ¶
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 implements a LIFO stack with peeking.
func (*Stack[T]) Peek ¶
func (s *Stack[T]) Peek() (t T)
Peek returns the stack's top element but does not remove it. If the stack is empty the zero value is returned.
func (*Stack[T]) Pop ¶
func (s *Stack[T]) Pop() (t T)
Pop removes the stack's top element and returns it. If the stack is empty it returns the zero value.
Click to show internal directories.
Click to hide internal directories.