Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 771 Bytes

2.md

File metadata and controls

45 lines (35 loc) · 771 Bytes
 private:
    stack<int> s;
        stack<int> s1;
public:
    void rev(stack<int>& s, stack<int>& s1) {
        while (!s.empty()) {
            s1.push(s.top());
            s.pop();
        }
    }
    MyQueue() {
    }

    void push(int x) { s.push(x); }

    int pop() {
        rev(s, s1);
        int t = s1.top();
        s1.pop();
        rev(s1, s);

        return t;
    }

    int peek() {

        rev(s, s1);
        int  t= s1.top();
        rev(s1, s);
        return t;
    }

    bool empty() {

        // if (s.size() == 0)
        //     return true;
        // return false;

        return s.empty();
    }