Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename Type>
- class Queue{
- public:
- void Push(const Type &element){
- if(stack1_.empty()){
- stack1_.push(element);
- return;
- }
- }
- void Pop(){
- if(!stack1_.empty()){
- Type last_elem = stack1_.top();
- if(last_elem < stack2_.top()){
- //stack1_.pop();
- //Push(last_elem);
- stack2_.push(last_elem);
- } else{
- stack1_.push(stack2_.top());
- }
- }
- }
- Type &Front(){
- if(!stack2_.empty()){
- Type last_elem = stack2_.top();
- if(last_elem < stack1_.top()){
- //stack2_.pop();
- //Push(last_elem);
- stack1_.push(last_elem);
- return stack1_.top();
- } else{
- stack2_.push(stack1_.top());
- return stack2_.top();
- }
- }else{
- return stack1_.top();
- }
- }
- uint64_t Size() const{return stack1_.size() + stack2_.size();}
- bool IsEmpty() const{return stack1_.empty() && stack2_.empty();}
- private:
- stack<Type> stack1_;
- stack<Type> stack2_;
- };
Advertisement
Add Comment
Please, Sign In to add comment