```go
package main
import "fmt"
/* 棧結(jié)構(gòu)*/
type Stackstruct {
val []interface{}
length uint32
}
/* 構(gòu)造一個(gè)空棧*/
func (S *Stack) InitStack() {
S.val = make([]interface{},0)
S.length =0
}
/* 銷毀棧*/
func (S *Stack) DestroyStack() {
S.ClearStack()
}
/* 清空棧*/
func (S *Stack) ClearStack() {
S.InitStack()
}
/* 判斷棧是否為空,空的話,返回true,不空返回false */
func (S *Stack) StackEmpty() bool {
if S.length <=0 {
return true
? }else {
return false
? }
}
/* 返回棧的長(zhǎng)度*/
func (S *Stack) StackLength() uint32 {
return S.length
}
/* 獲取棧頂元素*/
func (S *Stack) GetTop()interface{} {
return S.val[0]
}
/* 插入一個(gè)元素到棧中*/
func (S *Stack) Push(einterface{}) {
S.val = append(S.val, e)
S.length +=1
}
/* 出棧*/
func (S *Stack) Pop()interface{} {
if S.length ==0 {
return nil
}
e := S.val[0]
S.length -=1
? S.val = S.val[:S.length]
return e
}
/* 從棧低到棧頂依次對(duì)S的每個(gè)元素調(diào)用visit().一旦visit()失敗,則棧操作失敗*/
func (S *Stack) StackTraverse(visitfunc(a ...interface{}))? {
for i := uint32(0);i < S.length;i +=1 {
visit(S.val[i])
}
}
func p(a ...interface{}) {
fmt.Print(a[0]," ")
}
```