Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- int* mas;
- void qs(int* mas, int l, int r)
- {
- double x;
- int i, j, c = l, d = r, q;
- while (c < d)
- {
- x = (mas[c] + mas[d]) / 2;
- i = c;
- j = d;
- while (i < j)
- {
- while (mas[i] < x)
- i++;
- while (mas[j] > x)
- j--;
- if (i <= j)
- {
- swap(mas[i], mas[j]);
- i++;
- j--;
- }
- }
- if (j - c < d - i)
- {
- if (c < j)
- qs(mas, c, j);
- c = i;
- }
- else
- {
- if (i < d)
- qs(mas, i, d);
- d = j;
- }
- }
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n;
- cin >> n;
- mas = new int[n];
- for (int i = 0; i < n; i++)
- {
- cin >> mas[i];
- }
- int l = 0;
- int r = n - 1;
- qs(mas, l, r);
- for (int i = 0; i < n; i++)
- {
- cout << mas[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement