Advertisement
inwerp

Untitled

Jul 27th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1.         void pushback (T x)
  2.         {
  3.             size += 1;
  4.             if (size >= capacity) {
  5.                 reallocate(capacity*2);
  6.                 capacity = capacity*2;
  7.             }
  8.             data[size++] = x;
  9.         }
  10.         void reallocate(size_t s)
  11.         {
  12.             if (s < capacity)
  13.                 {
  14.                     std::cout << "what are you doing mazafuka" << std::endl;
  15.                     return;
  16.                 }
  17.             T* data_new = new T[s];
  18.             for(int it = 0; it != size ; ++it)
  19.                     {
  20.                         data_new[it] = data[it];
  21.  
  22.                     }
  23.             data = data_new;
  24.             delete[] data;
  25.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement