Advertisement
g-stoyanov

C++ copy elements demo

Jan 25th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. vector<int> copyElements(vector<int> array, vector<int>& array2, int n)
  2. {
  3.  
  4.     if (n == array.size())
  5.     {
  6.         return array2;
  7.     }
  8.     else
  9.     {
  10.         if (array[n] % 2 == 0)
  11.         {
  12.             array2.push_back(array[n]);
  13.         }
  14.  
  15.         return copyElements(array, array2, n + 1);
  16.     }
  17.  
  18. }
  19.  
  20. int main()
  21. {
  22.     //initialize the two vectors
  23.     vector<int> array;
  24.     for (int i = 0; i < 8; i++)
  25.     {
  26.         array.push_back(i);
  27.     }
  28.     vector<int> array2;
  29.  
  30.     copyElements(array, array2, 0);
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement