Untitled
user_9124840
plain_text
a year ago
664 B
11
Indexable
class MyStack {
queue<int> Q;
public:
MyStack() {}
void push(int x) {
queue<int> temp;
temp.push(x);
while (!Q.empty()) {
temp.push(Q.front());
Q.pop();
}
Q = temp;
}
int pop() {
int x = Q.front();
Q.pop();
return x;
}
int top() { return Q.front(); }
bool empty() { return Q.empty(); }
};
/**
* Your MyStack object will be instantiated and called as such:
* MyStack* obj = new MyStack();
* obj->push(x);
* int param_2 = obj->pop();
* int param_3 = obj->top();
* bool param_4 = obj->empty();
*/Editor is loading...
Leave a Comment