package main
import (
"fmt"
)
type StackQueue struct {
Arr []interface{}
}
func New(max int) *StackQueue{
sq:=new(StackQueue)
sq.Arr = make([]interface{},0, max)
return sq
}
//入栈
func (this *StackQueue) Push(value interface{}) {
n:=len(this.Arr)
this.Arr = append(this.Arr[:n],value)
}
//出栈
func (this *StackQueue) Pop() (interface{}) {
n:=len(this.Arr)
if(n<=0){
return nil
}
ele:=this.Arr[n-1]
this.Arr = append(this.Arr[:n-1])
return ele
}
//显示栈
func (this *StackQueue) Show() {
fmt.Printf("%d", this.Arr)
}
func main() {
s1:=New(1)
s1.Push(3)
s1.Push(22)
s1.Push(5)
ele:=s1.Pop()
fmt.Printf(" -> %d\n", ele)
s1.Show()
}
-> 5
[3 22]