You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
336 B
Go
18 lines
336 B
Go
package main
|
|
|
|
import "errors"
|
|
|
|
// Helper functions for slices, to make them behave more like stacks
|
|
func peek[T any](s []T) (T, error) {
|
|
if len(s) < 1 {
|
|
return *new(T), errors.New("Stack empty")
|
|
}
|
|
return s[len(s)-1], nil
|
|
}
|
|
|
|
func pop[T any](sp *[]T) T {
|
|
to_return := (*sp)[len(*sp)-1]
|
|
*sp = (*sp)[:len(*sp)-1]
|
|
return to_return
|
|
}
|