原題鏈接:劍指Offer09:用兩個(gè)棧實(shí)現(xiàn)隊(duì)列(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
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧