Question: Assume we have a DynamicVector class that when it fills to capacity and needs more space we call a function reserve(int) which will do the

Assume we have a DynamicVector class that when it fills to capacity and needs more space we call a function reserve(int) which will do the following:

Reserve a new larger capacity (if its actually larger)

Copy the previous values over to the new array

Delete the old array

Make sure our DynamicVector uses the new array

The following forward declaration with all of the DynamicVectors member variables should help. Implement void DynamicVector::reserve(int newCapacity)

class DynamicVector {

private:

int capacity; // current max capacity

int size; // number of elements in array

char* array; // array storing elements

void reserve(int); // new function to write

};

void DynamicVector::reserve(int newCapacity) {

// YOUR CODE GOES HERE

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!