Go语言用map实现堆栈功能
package stack import ( "strconv" ) type Stack struct { quenu map[int]int } func New() *Stack{ s := new(Stack) s.quenu = make(map[int]int) return s } func (s *Stack) Push(i int) { s.quenu[len(s.quenu)] = i } func (s *Stack) Pop() { delete(s.quenu, len(s.quenu)-1) } func (s *Stack) String() string { info := "" for i := 0; i < len(s.quenu); i++ { info = info + "[" + strconv.Itoa(i) + "," + strconv.Itoa(s.quenu[i]) + "]" } return info }