Created
July 19, 2022 12:40
-
-
Save icameling/dc6999e188dc21e2a6ba01d23ec5116e to your computer and use it in GitHub Desktop.
#栈与队列 #用栈实现队列
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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