Amonin

class queue

Dec 15th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <deque>
  5.  
  6. using std::cin;
  7. using std::cout;
  8. using std::vector;
  9. using std::ostream;
  10. using std::deque;
  11.  
  12. template <typename T, typename Container = deque<T>>
  13. class Queue {
  14. private:
  15.     Container body;
  16.  
  17. public:
  18.     Queue(const Container& c = {})
  19.             : body(c)
  20.     {}
  21.     T front() const {
  22.         return body.front();
  23.     }
  24.     T& front() {
  25.         return body.front();
  26.     }
  27.     void pop() {
  28.         body.pop_front();
  29.     }
  30.     void push(const T& elem) {
  31.         body.push_back(elem);
  32.     }
  33.     size_t size() const {
  34.         return body.size();
  35.     }
  36.     bool empty() const {
  37.         return body.empty();
  38.     }
  39.     bool operator == (const Queue<T>& other) const {
  40.         if (other.body.size() != body.size()) {
  41.             return false;
  42.         } else {
  43.             for (size_t i = 0; i != body.size(); ++i) {
  44.                 if (body[i] != other.body[i])
  45.                     return false;
  46.             }
  47.         }
  48.         return true;
  49.     }
  50.     bool operator != (const Queue<T>& other) const {
  51.         if (other.body.size() != body.size()) {
  52.             return true;
  53.         } else {
  54.             for (size_t i = 0; i != body.size(); ++i) {
  55.                 if (body[i] != other.body[i])
  56.                     return true;
  57.             }
  58.         }
  59.         return false;
  60.     }
  61. };
Advertisement
Add Comment
Please, Sign In to add comment