stack.go 673 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. // Stack ...
  3. type Stack []int
  4. // Top ...
  5. func (s Stack) Top() int {
  6. return s[len(s)-1]
  7. }
  8. // Empty ...
  9. func (s Stack) Empty() bool {
  10. return len(s) == 0
  11. }
  12. // Push ...
  13. func (s *Stack) Push(val int) {
  14. *s = append(*s, val)
  15. }
  16. // Pop ...
  17. func (s *Stack) Pop() int {
  18. top := s.Top()
  19. *s = (*s)[:len(*s)-1]
  20. return top
  21. }
  22. // Stack64 ...
  23. type Stack64 []int64
  24. // Top ...
  25. func (s Stack64) Top() int64 {
  26. return s[len(s)-1]
  27. }
  28. // Empty ...
  29. func (s Stack64) Empty() bool {
  30. return len(s) == 0
  31. }
  32. // Push ...
  33. func (s *Stack64) Push(val int64) {
  34. *s = append(*s, val)
  35. }
  36. // Pop ...
  37. func (s *Stack64) Pop() int64 {
  38. top := s.Top()
  39. *s = (*s)[:len(*s)-1]
  40. return top
  41. }