avr39ripe

cppArrReverse

Jul 12th, 2021
772
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3.  
  4. int main()
  5. {
  6.     const int arrSize{ 10 };
  7.     //int arr[arrSize]{ 1,-4,2,7,8,-6,1,-3,0,7 };
  8.     int arr[arrSize]{1,2,3,4,5,6,7,8,9,10};
  9.     int copy{};
  10.     //int arrRev[arrSize]{};
  11.     //int arr[arrSize]{};
  12.  
  13.    
  14.  
  15.     //for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
  16.  
  17.     /*for (int i{ 0 }; i < arrSize; ++i)
  18.     {
  19.         arr[i] = minRange + rand() % (maxRange - minRange + 1);
  20.     }*/
  21.  
  22.     for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
  23.  
  24.  
  25.     //for (int i{ 0 }; i < arrSize / 2; ++i)
  26.     //{
  27.     //  copy = arr[i];
  28.     //  arr[i] = arr[arrSize - 1 - i];
  29.     //  arr[arrSize - 1 - i] = copy;
  30.     //}
  31.  
  32.     for (int head{ 0 }, tail{arrSize - 1}; head < tail; ++head, --tail)
  33.     {
  34.         copy = arr[head];
  35.         arr[head] = arr[tail];
  36.         arr[tail] = copy;
  37.     }
  38.  
  39.     //for (int q{ 0 }, z{ arrSize - 1 }; q < z; ++q, --z)
  40.     //{
  41.     //  k = arr[q];
  42.     //  arr[q] = arr[z];
  43.     //  arr[z] = k;
  44.     //}
  45.  
  46.     //for (int i{ arrSize-1 }; i >= 0; --i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
  47.        
  48.     //for (int i{ 0 }; i < arrSize; ++i)
  49.     //{
  50.     //  arrRev[arrSize - 1 - i] = arr[i];
  51.     //}
  52.  
  53.     //for (int i{ 0 }; i < arrSize; ++i)
  54.     //{
  55.     //  arr[i] = arrRev[i];
  56.     //}
  57.  
  58.     std::cout << "Original arr:\n";
  59.     for (int i{ 0 }; i < arrSize; ++i) { std::cout << arr[i] << '\t'; } std::cout << '\n';
  60.     //std::cout << "Reversed copy arr:\n";
  61.     //for (int i{ 0 }; i < arrSize; ++i) { std::cout << arrRev[i] << '\t'; } std::cout << '\n';
  62.  
  63.     return 0;
  64. }
RAW Paste Data