Skip to content

Simple Generic Stack in Go using Linked List

License

Notifications You must be signed in to change notification settings

sv-tools/gstack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gstack

Simple Generic Stack implementation in Go using linked list

Usage

s := gstack.New(1, 2, 3, 4)
fmt.Println(s.Len())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
fmt.Println(s.Pop())
s.Push(5)
fmt.Println(s.Peek())
// Output: 4
// 4
// 3
// 2
// 1
// 5

Changelog

v0.1.0

  • minimal supported version of Go is 1.20
  • initial implementation

v1.0.0

  • minimal supported version of Go is 1.23
  • added Iter method to iterate over the stack and consume all items
s := gstack.New(1, 2, 3, 4)
for v := range s.Iter() {
    fmt.Println(v)
}
fmt.Println("len:", s.Len())
// Output: 4
// 3
// 2
// 1
// len: 0

v1.1.0

  • added IsEmpty method to check if the stack is empty