include [HTML_REMOVED]
int q[1000000];
int quickpai(int q[], int l, int r);
int main() {
int n;
scanf(“%d”, &n);
int i;
for (i = 0; i < n; i) {
scanf(“%d”, &q[i]);
}
quickpai(q, 0, n - 1);
for (i = 0; i < n; i) {
printf(“%d “, q[i]);
};
}
int quickpai(int q[], int l, int r) {
if (l >= r)
return 0;
int w = (q[l] + q[r]) / 2;
int y = l - 1;
int e = r + 1;
while (y < e) {
do {
y++;
} while (q[y] < w);
do {
e--;
} while (q[e] > w);
if (y < e) {
int swap = q[y];
q[y] = q[e];
q[e] = swap;
}
}
quickpai(q, l, e);
quickpai(q, e + 1, r);
return 0;
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla