1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <bits/stdc++.h> using namespace std;
int main() { int n; cin >> n; int list[n]; for (int i = 0; i < n; i++) { cin >> list[i]; } for (int i = 0; i < n; i++) { if (i == 0) continue; int lol = list[i]; int index = i; for (int j = i; j >= 0; j--) { if (list[j] > lol) { swap(list[j], list[index]); index--; } } } for (int i = 0; i < n; i++) { cout << list[i] << " "; } return 0; }
|