Think:
1知识点:sort()实现快速排序
2思考:通过两次快速排序实现交叉排序,分治思想
以下为Accepted代码
#include <bits/stdc++.h>
using namespace std;
int a[104], b[104];
int main(){
int n, i, tp1, tp2;
tp1 = tp2 = 0;
scanf("%d", &n);
for(i = 1; i <= n; i++){
if(i & 1)
scanf("%d", &a[tp1++]);
else
scanf("%d", &b[tp2++]);
}
sort(a, a+tp1);
sort(b, b+tp2, greater<int>());
int op1 = 0, op2 = 0;
for(i = 1; i <= n; i++){
if(i & 1)
printf("%d%c", a[op1++], i == n? '\n': ' ');
else
printf("%d%c", b[op2++], i == n? '\n': ' ');
}
return 0;
}
/***************************************************
User name:
Result: Accepted
Take time: 0ms
Take Memory: 244KB
Submit time: 2017-07-15 10:41:56
****************************************************/

本文介绍了一种使用快速排序实现交叉排序的方法,通过分别对奇数位置和偶数位置的元素进行排序来完成整个序列的排序过程。代码实现了读取输入、排序及输出的功能。

被折叠的 条评论
为什么被折叠?



