1. package stack
    2. import "container/list"
    3. type Stack struct {
    4. list *list.List
    5. }
    6. func NewStack() *Stack {
    7. return &Stack{
    8. list: list.New(),
    9. }
    10. }
    11. func (s *Stack) Push(v interface{}) {
    12. s.list.PushBack(v)
    13. }
    14. func (s *Stack) Pop() interface{} {
    15. if e := s.list.Back(); e != nil {
    16. return e.Value
    17. }
    18. return nil
    19. }
    20. func (s *Stack) Len() int {
    21. return s.list.Len()
    22. }
    23. func (s *Stack) IsEmpty() bool {
    24. return s.Len() == 0
    25. }