genstack

module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2022 License: MIT

README

genstack

A Generic Stack (FILO/LIFO) package for Go

 go get github.com/markekraus/genstack
package main

import (
    "fmt"
    genstack "github.com/markekraus/genstack/pkg"
)

type mytype struct {
    a, b int
}

func main() {
    s := genstack.New[int]()
    fmt.Printf("elements: %v, want: %v\n", s.Len(), 0)
    s.Push(3)
    s.Push(2)
    s.Push(90)
    fmt.Printf("elements: %v, want: %v\n", s.Len(), 3)
    for i := s.Len(); i > 0; i-- {
        m := s.Pop().Value
        fmt.Printf("elements: %v, want: %v\n", s.Len(), i)
        fmt.Printf("Value: %v\n", m)
    }

    s2 := genstack.New[*mytype*]()
    e1 := &mytype{1, 2}
    s2.Push(&mytype{1, 2})
    e2 := q.Pop().Value
    fmt.Printf("%v\n", e2 == e1)
    fmt.Printf("%v\n", e2.a == e1.a)
    fmt.Printf("%v\n", e2.b == e1.b)
}

Directories

Path Synopsis
Package genstack provides a generic FILO/LIFO stack.
Package genstack provides a generic FILO/LIFO stack.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL