Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1.  
  2. template <typename T>
  3. class SimpleVector
  4. {
  5. private:
  6.     T* x = new T[];
  7.     static int size;
  8. public:
  9.     SimpleVector(T*, int)
  10.     {
  11.     };
  12.  
  13.     void push_back(int x)
  14.     {
  15.         this->x[size] = x;
  16.         size++;
  17.     }
  18.     void getX(int size)
  19.     {
  20.         return x[size];
  21.     }
  22.     int find(T x)
  23.     {
  24.         int i = 0;
  25.         while (this->x[i] != x && i < size)
  26.         {
  27.             i++;
  28.         }
  29.         if (this->x[i] != x)
  30.             return -1;
  31.         return i;
  32.     }
  33.     void remove(T x)
  34.     {
  35.         int i = 0;
  36.         while (this->x[i] != x && i < size)
  37.         {
  38.             i++;
  39.         }
  40.         if (this->x[i] != x)
  41.             return;
  42.         for (int j = i + 1; j < size; j++)
  43.             this->x[j - 1] = this->x[j];
  44.         size--;        
  45.     }
  46.     bool insert_after(int x, int y)
  47.     {
  48.         int i = 0;
  49.         while (this->x[i] != y && i < size)
  50.         {
  51.             i++;
  52.         }  
  53.         if (this->x[i] != y)
  54.             return false;
  55.         size++;
  56.         for (int j = size - 1; j > i; j--)
  57.             this->x[j] = this->x[j - 1];
  58.         this->x[i] = x;
  59.         return true;
  60.     }
  61. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement