Sanlover

Untitled

Oct 25th, 2021
636
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int N;
  8.     int *array;
  9.  
  10.     cout << "Enter size: ";
  11.     cin >> N;
  12.     if (N <= 1)
  13.     {
  14.         cout << "N should be [2; +inf)" << endl;
  15.         return 0;
  16.     }
  17.  
  18.     array = new int[N];
  19.     cout << endl << "Fill the array: " << endl;
  20.     for (int i = 0; i < N; i++)
  21.     {
  22.         cout << "[" << i << "] = ";
  23.         cin >> array[i];
  24.     }
  25.  
  26.     int middle = N / 2;
  27.     for (int i = 0; i < middle; i += 2)
  28.     {
  29.         int temp = array[i];
  30.         array[i] = array[middle + i];
  31.         array[middle + i] = temp;
  32.     }
  33.     if (N % 2 != 0)
  34.     {
  35.         int temp = array[middle + 1];
  36.         array[middle + 1] = array[N - 1];
  37.         array[N - 1] = temp;
  38.     }
  39.  
  40.     cout << endl << "Array after applying some type of sort: " << endl;
  41.     for (int i = 0; i < N; i++)
  42.     {
  43.         cout << array[i] << " ";
  44.     }
  45.     return 0;
  46. }
  47.  
RAW Paste Data