avr39ripe

cppTwoSmallToOneBigArrSorting

Jul 12th, 2021
1,000
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 bigSize{ 10 };
  7.     const int smallSize{ bigSize / 2 };
  8.     enum Condition{greater, equal, less, maxCond};
  9.  
  10.     int arrSmallA[smallSize]{ 1,2,-3,0,4 };
  11.     int arrSmallB[smallSize]{ -1,0,3,6,-5 };
  12.     int arrBig[bigSize]{};
  13.     int bigIdx{ 0 };
  14.  
  15.     for (int cond{ Condition::greater }; cond < Condition::maxCond; ++cond)
  16.     {
  17.         for (int smallIdx{ 0 }; smallIdx < smallSize; ++smallIdx)
  18.         {
  19.             if (cond == Condition::greater)
  20.             {
  21.                 if (arrSmallA[smallIdx] > 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  22.                 if (arrSmallB[smallIdx] > 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  23.             }
  24.             else if (cond == Condition::equal)
  25.             {
  26.                 if (arrSmallA[smallIdx] == 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  27.                 if (arrSmallB[smallIdx] == 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  28.             }
  29.             else if (cond == Condition::less)
  30.             {
  31.                 if (arrSmallA[smallIdx] < 0) { arrBig[bigIdx++] = arrSmallA[smallIdx]; }
  32.                 if (arrSmallB[smallIdx] < 0) { arrBig[bigIdx++] = arrSmallB[smallIdx]; }
  33.             }
  34.         }
  35.     }
  36.    
  37.     for (bigIdx = 0; bigIdx < bigSize; ++bigIdx)
  38.     {
  39.         std::cout << arrBig[bigIdx] << ' ';
  40.     }
  41.     std::cout << '\n';
  42.     return 0;
  43. }
RAW Paste Data