Skip to content

Instantly share code, notes, and snippets.

@icameling
Created July 19, 2022 12:40
Show Gist options
  • Save icameling/dc6999e188dc21e2a6ba01d23ec5116e to your computer and use it in GitHub Desktop.
Save icameling/dc6999e188dc21e2a6ba01d23ec5116e to your computer and use it in GitHub Desktop.
#栈与队列 #用栈实现队列
class MyQueue {
public:
MyQueue() {
}
void push(int x) {
my_deque_.push_back(x);
}
int pop() {
int i = my_deque_.front();
my_deque_.pop_front();
return i;
}
int peek() {
return my_deque_.front();
}
bool empty() {
return my_deque_.empty();
}
private:
deque<int> my_deque_;
};
/**
* Your MyQueue object will be instantiated and called as such:
* MyQueue* obj = new MyQueue();
* obj->push(x);
* int param_2 = obj->pop();
* int param_3 = obj->peek();
* bool param_4 = obj->empty();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment