allia

неудачный xoar

Sep 21st, 2020
1,063
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. void sorti(int *arr, int left, int right, int key)
  7. {
  8.   int a = right;
  9.   int b = left;
  10.  
  11.   while (right > left)
  12. {
  13.    while (arr[right]>=key && right > left)
  14.    right--;
  15.    if (right!=left)
  16.    {
  17.      arr[left]=arr[right];
  18.    left++;
  19.    }
  20.    while (arr[left]<=key && right > left)
  21.    left++;
  22.    if (right!=left)
  23.    {
  24.      arr[right] = arr[left];
  25.    right--;
  26.    }
  27. }
  28.  
  29. arr[left] = key;
  30. key = left;
  31. left = b;
  32. right = a;
  33.  
  34. if (left < key)
  35. sorti (arr, left, key-1, arr[left]);
  36. if (right > key)
  37. sorti (arr, key+1, right, arr[key+1]);
  38. }
  39.  
  40. int main ()
  41. {
  42.   int n = 0;
  43.   cin >> n;
  44.   int *arr;
  45.   arr = new int [n];
  46.  
  47.   for (int i=0; i<n; i++)
  48.   cin >> arr[i];
  49.  
  50.   int right = n-1;
  51.   int left = 0;
  52.   int key = arr[0];
  53.  
  54.   sorti(arr, left, right, key);
  55.  
  56.   for (int i=0; i<n; i++)
  57.   cout << arr[i] << " ";
  58. }
  59.  
  60.  
RAW Paste Data