Advertisement
thouxanbanuno

deque vv

Sep 24th, 2021
991
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <string>
  4. #include <utility>
  5. #include <vector>
  6. #include "test_runner.h"
  7. using namespace std;
  8.  
  9. template <typename T> class Deque{
  10. public:
  11.     Deque(){}
  12.     bool Empty()const{
  13.         if(_back.empty() && _front.empty())
  14.             return true;
  15.         return false;
  16.     }
  17.     size_t Size() const{
  18.         return(_front.size() + _back.size());
  19.     }
  20.     const T& operator[](size_t index) const{
  21.         if(index + 1 > _front.size()){
  22.             return (_back[index - _front.size()]);
  23.         }
  24.     }
  25.     T& operator[]( size_t index){
  26.         if(index + 1 > _front.size()){
  27.             return (_back[index - _front.size()]);
  28.         }
  29.     }
  30.     const T& At(size_t index) const  {
  31.         if(index >= _front.size() + _back.size())
  32.             throw out_of_range("deq");
  33.         if(index + 1 > _front.size()){
  34.             return (&_back[index - _front.size()]);
  35.         }
  36.     }
  37.     T& At(size_t index){
  38.         if(index >= _front.size() + _back.size())
  39.             throw out_of_range("deq");
  40.         if(index + 1 > _front.size()){
  41.             return (&_back[index - _front.size()]);
  42.         }
  43.     }
  44.     T& Front() const{
  45.         if(!_front.empty())
  46.             return &_front.front();
  47.     }
  48.     T& Front(){
  49.         if(!_front.empty())
  50.             return &_front.front();
  51.     }
  52.     T& Back() const{
  53.         if(!_back.empty())
  54.             return &_back.back();
  55.     }
  56.     T& Back(){
  57.         if(!_back.empty())
  58.             return &_back.back();
  59.     }
  60.     void PushFront(const T& val){
  61.         _front.push_back(val);
  62.     }
  63.     void PushBack(const T& val){
  64.         _back.push_back(val);
  65.     }
  66. private:
  67.     vector<T> _front,_back;
  68.     vector<T> v;
  69. };
  70. void TestDeque() {
  71.  
  72. }
  73.  
  74. int main() {
  75.   TestRunner tr;
  76.   RUN_TEST(tr, TestDeque);
  77.   return 0;
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement