123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package main
- // Stack ...
- type Stack []int
- // Top ...
- func (s Stack) Top() int {
- return s[len(s)-1]
- }
- // Empty ...
- func (s Stack) Empty() bool {
- return len(s) == 0
- }
- // Push ...
- func (s *Stack) Push(val int) {
- *s = append(*s, val)
- }
- // Pop ...
- func (s *Stack) Pop() int {
- top := s.Top()
- *s = (*s)[:len(*s)-1]
- return top
- }
- // Stack64 ...
- type Stack64 []int64
- // Top ...
- func (s Stack64) Top() int64 {
- return s[len(s)-1]
- }
- // Empty ...
- func (s Stack64) Empty() bool {
- return len(s) == 0
- }
- // Push ...
- func (s *Stack64) Push(val int64) {
- *s = append(*s, val)
- }
- // Pop ...
- func (s *Stack64) Pop() int64 {
- top := s.Top()
- *s = (*s)[:len(*s)-1]
- return top
- }
|