So i have an array called digits that has dynamic allocated memory. The initial capacity is set to a default capacity of 20. I'm trying to figure out how to implement the following code so that if something is added to the array that exceeds the capacity the code will create a new array that is 2^n bigger (i.e. 40, 80, 160). however i want it to have a for loop that will make the array 2^n bigger until the new capacity is larger then what was entered.
void BigNum::resize(size_t n)
{
size_t *NEW_CAPACITY;
if(n == capacity)
return; // The allocated memory is already the right size
if(n < used)
n = used;
NEW_CAPACITY = new size_t[n];
copy(digits, digits + used, NEW_CAPACITY);
delete[] digits;
digits = NEW_CAPACITY;
capacity = n;
Any help is much appreciated