Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale.h>
- using namespace std;
- void quicksort(int *mas, int first, int last)
- {
- int mid, count;
- int f = first, l = last;
- mid = mas[(f + l) / 2];
- do
- {
- while (mas[f] < mid) f++;
- while (mas[l] > mid) l--;
- if (f <= l)
- {
- count = mas[f];
- mas[f] = mas[l];
- mas[l] = count;
- f++;
- l--;
- }
- } while (f < l);
- if (first < l) quicksort(mas, first, l);
- if (f < last) quicksort(mas, f, last);
- }
- int atoi(char *s, int l, int r) {
- int mn = 1;
- int ans = 0;
- for (int i = r; i >= l; i--) {
- ans += (s[i] - '0')*mn;
- mn *= 10;
- }
- return ans;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- char s[80];
- int a[80];
- int id = 0;
- cout << "Введите строку" << endl;
- gets_s(s);
- system("CLS");
- cout << "Введённая строка - " << s << endl;
- int i = 0;
- int l, r;
- while (i < strlen(s)) {
- l = i;
- while (s[i] != ' ' && i < strlen(s)) i++;
- r = i - 1;
- a[id++] = atoi(s, l, r);
- i++;
- }
- quicksort(a, 0, id - 1);
- cout << "Отсортированные числа" << endl;
- for (int i = 0; i < id; i++) {
- cout << a[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement