//#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int ans[1000];
void print(int* a)
{
for (int i = 1; i <= a[0]; i++)
cout << a[i] << ' ';
cout << endl;
}
void sort(int* ans,int start,int end)
{
if (start >= end)
return;
int key = ans[start];
int i = start, j = end;
while (i < j) {
while (i < j && ans[j] >= key) j--;
ans[i] = ans[j];
while (i < j && ans[i] <= key) i++;
ans[j] = ans[i];
}
ans[j] = key;
print(ans);
sort(ans, start, i - 1);
sort(ans, i + 1 , end);
}
int main()
{
int i, n;
cin >> n;
ans[0] = n;
for (i = 1; i <= n; i++)
cin >> ans[i];
sort(ans,1,n);
}
时间限制:1000MS 代码长度限制:10KB
提交次数:2105 通过次数:1352
题型: 编程题 语言: G++;GCC
Description
用函数实现快速排序,并输出每次分区后排序的结果
输入格式
第一行:键盘输入待排序关键的个数n 第二行:输入n个待排序关键字,用空格分隔数据
输出格式
每行输出每趟排序的结果,数据之间用一个空格分隔
输入样例
10 5 4 8 0 9 3 2 6 7 1
输出样例
1 4 2 0 3 5 9 6 7 8 0 1 2 4 3 5 9 6 7 8 0 1 2 4 3 5 9 6 7 8 0 1 2 3 4 5 9 6 7 8 0 1 2 3 4 5 8 6 7 9 0 1 2 3 4 5 7 6 8 9 0 1 2 3 4 5 6 7 8 9
提示
作者
yqm
Version:
0