github.com/qiuhoude/go-web@v0.0.0-20220223060959-ab545e78f20d/algorithm/datastructures/stack/example_statck_test.go (about) 1 package stack 2 3 import "fmt" 4 5 func Example() { 6 //创建一个stack 7 s := New() 8 s.Push(5) 9 s.Push(4) 10 s.Push(3) 11 s.Push(2) 12 p := s.Pop() 13 fmt.Println(p) 14 fmt.Println(s.Len()) 15 16 for !s.IsEmpty() { 17 fmt.Println(s.Pop()) 18 } 19 20 //Output: 21 //2 22 //3 23 //3 24 //4 25 //5 26 }