Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Vector::push_back(const int & val)
- {
- if (this->_size < this->_capacity) {
- this->_elements[this->_size] = val;
- this->_size++;
- }
- else {
- int new_capacity = this->_capacity + this->_resizeFactor;
- std::cout << "new cap " << new_capacity;
- int* elements = new int[new_capacity];
- for (int i = 0; i < this->_size; ++i)
- {
- elements[i] = this->_elements[i];
- }
- this->~Vector();
- this->_capacity = new_capacity;
- elements[this->_size] = val;
- this->_size++;
- this->_elements = elements;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement