nochnoikoshmar1

Untitled

Apr 27th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. template <typename Type>
  2. class Queue{
  3. public:
  4.     void Push(const Type &element){
  5.         if(stack1_.empty()){
  6.             stack1_.push(element);
  7.             return;
  8.         }
  9.     }
  10.     void Pop(){
  11.         if(!stack1_.empty()){
  12.             Type last_elem = stack1_.top();
  13.             if(last_elem < stack2_.top()){
  14.                 //stack1_.pop();
  15.                 //Push(last_elem);
  16.                 stack2_.push(last_elem);
  17.             } else{
  18.                 stack1_.push(stack2_.top());
  19.             }
  20.         }        
  21.     }
  22.     Type &Front(){
  23.         if(!stack2_.empty()){
  24.             Type last_elem = stack2_.top();
  25.             if(last_elem < stack1_.top()){
  26.                 //stack2_.pop();
  27.                 //Push(last_elem);
  28.                 stack1_.push(last_elem);
  29.                 return stack1_.top();
  30.             } else{
  31.                 stack2_.push(stack1_.top());
  32.                 return stack2_.top();
  33.             }            
  34.         }else{
  35.             return stack1_.top();
  36.         }
  37.     }
  38.     uint64_t Size() const{return stack1_.size() + stack2_.size();}
  39.     bool IsEmpty() const{return stack1_.empty() && stack2_.empty();}
  40.  
  41. private:
  42.     stack<Type> stack1_;
  43.     stack<Type> stack2_;
  44. };
Advertisement
Add Comment
Please, Sign In to add comment