SHARE
TWEET

C++ copy elements demo

g-stoyanov Jan 25th, 2015 212 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top