classCQueue:def__init__(self):self.stk1=[]self.stk2=[]defappendTail(self,value:int)->None:self.stk1.append(value)defdeleteHead(self)->int:ifnotself.stk2:whileself.stk1:self.stk2.append(self.stk1.pop())return-1ifnotself.stk2elseself.stk2.pop()# Your CQueue object will be instantiated and called as such:# obj = CQueue()# obj.appendTail(value)# param_2 = obj.deleteHead()
classCQueue{privateDeque<Integer>stk1=newArrayDeque<>();privateDeque<Integer>stk2=newArrayDeque<>();publicCQueue(){}publicvoidappendTail(intvalue){stk1.push(value);}publicintdeleteHead(){if(stk2.isEmpty()){while(!stk1.isEmpty()){stk2.push(stk1.pop());}}returnstk2.isEmpty()?-1:stk2.pop();}}/** * Your CQueue object will be instantiated and called as such: * CQueue obj = new CQueue(); * obj.appendTail(value); * int param_2 = obj.deleteHead(); */
classCQueue{public:CQueue(){}voidappendTail(intvalue){stk1.push(value);}intdeleteHead(){if(stk2.empty()){while(!stk1.empty()){stk2.push(stk1.top());stk1.pop();}}if(stk2.empty()){return-1;}intans=stk2.top();stk2.pop();returnans;}private:stack<int>stk1,stk2;};/** * Your CQueue object will be instantiated and called as such: * CQueue* obj = new CQueue(); * obj->appendTail(value); * int param_2 = obj->deleteHead(); */
typeCQueuestruct{stk1,stk2[]int}funcConstructor()CQueue{returnCQueue{[]int{},[]int{}}}func(this*CQueue)AppendTail(valueint){this.stk1=append(this.stk1,value)}func(this*CQueue)DeleteHead()int{iflen(this.stk2)==0{forlen(this.stk1)>0{this.stk2=append(this.stk2,this.stk1[len(this.stk1)-1])this.stk1=this.stk1[:len(this.stk1)-1]}}iflen(this.stk2)==0{return-1}ans:=this.stk2[len(this.stk2)-1]this.stk2=this.stk2[:len(this.stk2)-1]returnans}/** * Your CQueue object will be instantiated and called as such: * obj := Constructor(); * obj.AppendTail(value); * param_2 := obj.DeleteHead(); */
classCQueue{privatestk1:number[];privatestk2:number[];constructor(){this.stk1=[];this.stk2=[];}appendTail(value:number):void{this.stk1.push(value);}deleteHead():number{if(this.stk2.length==0){while(this.stk1.length){this.stk2.push(this.stk1.pop());}}returnthis.stk2.length==0?-1:this.stk2.pop();}}/** * Your CQueue object will be instantiated and called as such: * var obj = new CQueue() * obj.appendTail(value) * var param_2 = obj.deleteHead() */
structCQueue{s1:Vec<i32>,s2:Vec<i32>,}/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */implCQueue{fnnew()->Self{CQueue{s1:Vec::new(),s2:Vec::new(),}}fnappend_tail(&mutself,value:i32){self.s1.push(value);}fndelete_head(&mutself)->i32{matchself.s2.pop(){Some(value)=>value,None=>{while!self.s1.is_empty(){self.s2.push(self.s1.pop().unwrap());}self.s2.pop().unwrap_or(-1)}}}}
varCQueue=function(){this.stk1=[];this.stk2=[];};/** * @param {number} value * @return {void} */CQueue.prototype.appendTail=function(value){this.stk1.push(value);};/** * @return {number} */CQueue.prototype.deleteHead=function(){if(!this.stk2.length){while(this.stk1.length){this.stk2.push(this.stk1.pop());}}returnthis.stk2.length?this.stk2.pop():-1;};/** * Your CQueue object will be instantiated and called as such: * var obj = new CQueue() * obj.appendTail(value) * var param_2 = obj.deleteHead() */
publicclassCQueue{privateStack<int>stk1=newStack<int>();privateStack<int>stk2=newStack<int>();publicCQueue(){}publicvoidAppendTail(intvalue){stk1.Push(value);}publicintDeleteHead(){if(stk2.Count==0){while(stk1.Count!=0){stk2.Push(stk1.Pop());}}returnstk2.Count==0?-1:stk2.Pop();}}/** * Your CQueue object will be instantiated and called as such: * CQueue obj = new CQueue(); * obj.AppendTail(value); * int param_2 = obj.DeleteHead(); */
classCQueue{privatevarstk1:[Int]=[]privatevarstk2:[Int]=[]init(){}funcappendTail(_value:Int){stk1.append(value)}funcdeleteHead()->Int{ifstk2.isEmpty{while!stk1.isEmpty{stk2.append(stk1.removeLast())}}returnstk2.isEmpty?-1:stk2.removeLast()}}/** * Your CQueue object will be instantiated and called as such: * let obj = CQueue(); * obj.appendTail(value); * let param_2 = obj.DeleteHead(); */