两个栈实现队列
class MyQueue { public: void push(int key) { stack1.push(key); } int pop() { if(stack2.empty()) { while(!stack1.empty()) { int temp=stack1.top(); stack1.pop(); stack2.push(temp); } } if(stack2.empty()) throw exception; int result=stack2.top(); stack2.pop(); return result; } private: stack<int> stack1; stack<int> stack2; };
posted on 2017-09-22 11:12 www_practice 阅读(98) 评论(0) 收藏 举报
 
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号