用两个栈模拟队列

class CQueue {
public:
    stack<int> s1;
    stack<int> s2;
    CQueue() {
       while(!s1.empty()){
           s1.pop();
       }
       while(!s2.empty()){
           s2.pop();
       }
    }
    
    void appendTail(int value) {
        s1.push(value);
    }
    
    int deleteHead() {
        if(!s2.empty()){
            
        }
        else{
            if(s1.empty())
                return -1;
            while(!s1.empty()){
            s2.push(s1.top());
            s1.pop();
            }
        }
        int re=s2.top();
        s2.pop();
        return re;
        
    }
};

/**
 * Your CQueue object will be instantiated and called as such:
 * CQueue* obj = new CQueue();
 * obj->appendTail(value);
 * int param_2 = obj->deleteHead();
 */

上一篇:Python高级培训第六课


下一篇:实验1 8086汇编指令编码和调试