剑指Offer09:用两个栈实现队列(Go语言)-创新互联
原题链接:剑指Offer09:用两个栈实现队列(Go语言)
辣鸡GoLang
!哼!
package main
type CQueue struct {inStack, outStack []int
}
func Constructor() CQueue {return CQueue{}
}
func (this *CQueue) AppendTail(value int) {this.inStack = append(this.inStack, value)
}
func (this *CQueue) in2out() {for len(this.inStack) >0 {this.outStack = append(this.outStack, this.inStack[len(this.inStack)-1])
this.inStack = this.inStack[:len(this.inStack)-1]
}
}
func (this *CQueue) DeleteHead() int {if len(this.outStack) == 0 {if len(this.inStack) == 0 { return -1
}
this.in2out()
}
value := this.outStack[len(this.outStack)-1]
this.outStack = this.outStack[:len(this.outStack)-1]
return value
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
当前题目:剑指Offer09:用两个栈实现队列(Go语言)-创新互联
分享地址:http://hbruida.cn/article/dcjpei.html