LintCode-剑指Offer-(40)用栈实现队列

来源:互联网 发布:centos 安装不上ibus 编辑:程序博客网 时间:2024/06/01 09:10
class Queue {public:stack<int> stack1;   stack<int> stack2;    Queue() {    // do intialization if necessary    }    void push(int element) {    // write your code here        while(stack1.empty()==false){            stack2.push(stack1.top());            stack1.pop();        }        stack1.push(element);        while(stack2.empty()==false){            stack1.push(stack2.top());            stack2.pop();        }}int pop() {    // write your code here    int tmp=stack1.top();    stack1.pop();    return tmp;}int top() {    // write your code here    return stack1.top();    }};
0 0