Created
September 15, 2020 12:48
-
-
Save oludouglas/01bddb3740b85568e761cac5a3d638b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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