A simple, thread-safe stack (LIFO) implementation in Go.
go get github.com/VxDant/stack-libpackage main
import (
"fmt"
"github.com/VxDant/stack-lib"
)
func main() {
s := stack.New()
// Push elements
s.Push("first")
s.Push("second")
s.Push("third")
// Pop element
value := s.Pop()
fmt.Println(value) // Output: third
// Print stack
fmt.Println(s) // Output: Stack[first second]
}New() *Stack
Creates and returns a new empty stack.
Push(value interface{})
Adds an element to the top of the stack.
Pop() interface{}
Removes and returns the top element. Returns nil if stack is empty.
String() stringReturns a string representation of the stack.
Thread-safe operations using sync.RWMutex
Simple and intuitive API
Works with any data type using interface{}
Contributions are welcome! Feel free to open issues or submit pull requests.