1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
type CQueue struct {
stack1 []int
stack2 []int
}
func Constructor() CQueue {
return CQueue{
stack1: []int{},
stack2: []int{},
}
}
func (this *CQueue) AppendTail(value int) {
this.stack1 = append(this.stack1, value)
}
func (this *CQueue) DeleteHead() int {
if len(this.stack2) == 0 {
for len(this.stack1) > 0 {
this.stack2 = append(this.stack2, this.stack1[len(this.stack1)-1])
this.stack1 = this.stack1[:len(this.stack1)-1]
}
}
if len(this.stack2) == 0 {
return -1
}
res := this.stack2[len(this.stack2)-1]
this.stack2 = this.stack2[:len(this.stack2)-1]
return res
}
|