Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
➜ stack cat main.go
package stack
type stack struct {
head int
values []int
}
type Stack interface {
Push(int)
Pop() int
Len() int
}
func (s *stack) Len() int {
return s.head
}
func New(size int) Stack {
return &stack{0, make([]int, size)}
}
func (s *stack) Push(value int) {
s.values[s.head] = value
s.head++
}
func (s *stack) Pop() int {
ret := s.values[s.head-1]
s.head--
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment