Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale.h>
- #include <vector>
- #include <algorithm>
- using namespace std;
- void mysort(vector<int>& v) {
- int amin = *min_element(v.begin(), v.end());
- int amax = *max_element(v.begin(), v.end());
- vector<int> b(amax - amin + 1, amax + 1);
- for (int i = 0; i < v.size(); ++i) b[v[i] - amin] = i;
- vector<int> res(v.size());
- int ind = 0;
- for (auto& x : res) {
- while (b[ind] == amax + 1) ++ind;
- x = v[b[ind++]];
- }
- v = res;
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- int n;
- cout << "Введите длину массива: ";
- cin >> n;
- cout << "Введите массив: ";
- vector<int> v(n);
- for (auto& x : v) cin >> x;
- mysort(v);
- for (auto& x : v) cout << x << " ";
- cout << endl;
- }
Add Comment
Please, Sign In to add comment