C++//没有不会的人吧(逃
//快速排序板子
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
void sortt(int l, int r) {
if (l >= r) return;
int i = l, j = r;
int k = a[(l + r) / 2];
do {
while (a[i] < k) i++;
while (a[j] > k) j--;
if (i <= j) {
swap(a[i], a[j]);
i++; j--;
}
} while (i <= j);
sortt(l, j);
sortt(i, r);
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sortt(1, n);
for (int i = 1; i <= n; i++) {
cout << a[i] << " ";
}
return 0;
}
//归并排序板子
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], b[N];
void msort(int l, int r) {
if (l >= r) return;
int mid = (l + r) / 2;
msort(l, mid);
msort(mid + 1, r);
int i = l, j = mid + 1, k = l;
while (i <= mid && j <= r) {
if (a[i] < a[j]) b[k++] = a[i++];
else b[k++] = a[j++];
}
while (i <= mid) b[k++] = a[i++];
while (j <= r) b[k++] = a[j++];
for (int i = l; i <= r; i++) a[i] = b[i];
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
msort(1, n);
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
return 0;
}
//堆排序板子
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, a[N], cnt = 0;
void up(int x) {
while (x / 2 >= 1 && a[x] < a[x / 2]) {
swap(a[x], a[x / 2]);
x /= 2;
}
}
void down(int x) {
int t = x;
if (2 * x <= cnt && a[t] > a[2 * x]) {
t = 2 * x;
}
if (2 * x + 1 <= cnt && a[t] > a[2 * x + 1]) {
t = 2 * x + 1;
}
if (t != x) {
swap(a[t], a[x]);
down(t);
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
up(++cnt);
}
for (int i = 1; i <= n; i++) {
cout << a[1] << " ";
swap(a[1], a[cnt--]);
down(1);
}
return 0;
}
//RADIX SORT 基数排序
#include <bits/stdc++.h>
using namespace std;
int a[100010], n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int k = 0; k <= 9; k++) {
int M = pow(10, k);
vector <int> g[10];
for (int i = 1; i <= n; i++) {
g[a[i] / M % 10].push_back(a[i]);
}
int u = 0;
for (int i = 0; i <= 9; i++) {
for (int t : g[i]) a[++u] = t;
}
}
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
return 0;
}