Advertisement
NickG

Untitled

Sep 22nd, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. string* allocateAndCopyToNewArray( string* pOldArray, int oldNumEntries, int newCapacity )
  2. {
  3.     string* str = new string[newCapacity];
  4.  
  5.     if(newCapacity > oldNumEntries)
  6.     {
  7.         std::copy(mWords, mWords+oldNumEntries, str);
  8.     }
  9.     else
  10.     {
  11.         std::copy(mWords, mWords+newCapacity, str);
  12.     }
  13.     return str;
  14. }
  15.  
  16. void DynamicArray::resize( int newCapacity )
  17. {
  18.     string *str = allocateAndCopyToNewArray(mWords, mNumWords, newCapacity);
  19.  
  20.     delete [] mWords;
  21.     mCapacity = newCapacity;
  22.     mWords = str;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement