Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. void MyDynamicArray::add(int v)
  2. {
  3.     nums = nums +1;
  4.     if (nums>capacity) //doubles when capcity is reached
  5.     {
  6.         //time to double
  7.         cout << "Doubling to : " << capacity * 2 << endl;
  8.         capacity = capacity * 2;
  9.     }
  10.     int *temp;
  11.     temp = new int[capacity];
  12.     for( int x=0; x<nums; x++) //temp array to push numbers over
  13.     {
  14.         temp[x] = array[x];
  15.     }
  16.     temp[nums-1] = v;
  17.     delete [] array;
  18.     array = temp;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement