func(this *MyQueue) Pop() int { for !this.Stack1.Empty() { if v, ok := this.Stack1.Pop(); ok { this.Stack2.Push(v) } } value, _ := this.Stack2.Pop() for !this.Stack2.Empty() { if v, ok := this.Stack2.Pop(); ok { this.Stack1.Push(v) } } return value.(int) }
func(this *MyQueue) Peek() int { for !this.Stack1.Empty() { if v, ok := this.Stack1.Pop(); ok { this.Stack2.Push(v) } } value, _ := this.Stack2.Peek() for !this.Stack2.Empty() { if v, ok := this.Stack2.Pop(); ok { this.Stack1.Push(v) } } return value.(int) }
func(this *MyStack) Pop() int { for i := 0; i < this.Queue1.Size()-1; i++ { v, _ := this.Queue1.Dequeue() value := v.(int) this.Queue1.Enqueue(value) } v, _ := this.Queue1.Dequeue() value := v.(int) return value }
func(this *MyStack) Top() int { top := 0 for i := 0; i < this.Queue1.Size(); i++ { v, _ := this.Queue1.Dequeue() value := v.(int) this.Queue1.Enqueue(value) if i == this.Queue1.Size()-1 { top = value } } return top }