剑指 Offer 09. 用两个栈实现队列

class CQueue {
public:

    stack<int> a;
    stack<int> b;

    CQueue() {

    }

    void appendTail(int value) {
        a.push(value);
    }

    int deleteHead() {
        if (b.empty())
        {
            while (!a.empty())
            {
                b.push(a.top());
                a.pop();
            }
        }

        if (b.empty())
        {
            return -1;
        }
        else
        {
            int val = b.top();
            b.pop();
            return val;
        }

    }
};
上一篇:[HNUOJ 10045] Joseph‘s Puzzle


下一篇:构造函数初始化和赋值的区别