-
-
Save Gitart/68419521e6c1453caf080ae402ee85c8 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
type Stack struct { | |
store []interface{} | |
} | |
func (s *Stack) IsEmpty() bool { | |
return len(s.store) == 0 | |
} | |
func (s *Stack) Size() int { | |
return len(s.store) | |
} | |
func (s *Stack) Push(item interface{}) { | |
s.store = append(s.store, item) | |
} | |
func (s *Stack) Peek() interface{} { | |
if s.IsEmpty() { | |
return nil | |
} | |
return s.store[len(s.store)-1] | |
} | |
func (s *Stack) Pop() interface{} { | |
if s.IsEmpty() { | |
return nil | |
} | |
v := s.store[len(s.store)-1] | |
s.store = s.store[:len(s.store)-1] | |
return v | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment