Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GStack ¶
type GStack[T any] struct { // contains filtered or unexported fields }
GStack is generic Stack implementation using linked list
Example ¶
package main
import (
"fmt"
"github.com/sv-tools/gstack"
)
func main() {
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
func New ¶
New creates an instance of GStack and pushes all given items to the created stack in reversed order
func (*GStack[T]) Iter ¶ added in v1.0.0
Iter returns a consuming iterator for the stack
Example ¶
package main
import (
"fmt"
"github.com/sv-tools/gstack"
)
func main() {
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
func (*GStack[T]) Peek ¶
func (s *GStack[T]) Peek() T
Peek returns the top item without removing it or a zero object of given type
Click to show internal directories.
Click to hide internal directories.