Last active
August 29, 2015 14:14
-
-
Save shinpei/602faaff5af1f3f725d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ 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