Skip to content

Instantly share code, notes, and snippets.

@shinpei
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinpei/602faaff5af1f3f725d7 to your computer and use it in GitHub Desktop.
Save shinpei/602faaff5af1f3f725d7 to your computer and use it in GitHub Desktop.
➜ 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