Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. void Vector::push_back(const int & val)
  2. {
  3. if (this->_size < this->_capacity) {
  4. this->_elements[this->_size] = val;
  5. this->_size++;
  6. }
  7. else {
  8. int new_capacity = this->_capacity + this->_resizeFactor;
  9. std::cout << "new cap " << new_capacity;
  10. int* elements = new int[new_capacity];
  11. for (int i = 0; i < this->_size; ++i)
  12. {
  13. elements[i] = this->_elements[i];
  14. }
  15. this->~Vector();
  16. this->_capacity = new_capacity;
  17. elements[this->_size] = val;
  18. this->_size++;
  19. this->_elements = elements;
  20.  
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement