sdnu1521手写qsort排序

1521.排序
Time Limit: 1000 MS Memory Limit: 32768 KB
Total Submission(s): 83 Accepted Submission(s): 32
Description
将输入的数从小到大排序。
Input
输入数据n(1<=n<=1000000)

接下来输入n个数据

(多组输入数据)
Output
按格式输出排序后的n个数。
Sample Input

5
5 3 4 6 8

Sample Output

3 4 5 6 8

Source
Unknown

#include
#include
#include
#include
#include
#include
#include
using namespace std;
int a[1000001];
void qsort(int a[], int low, int high)
{
    if(low>=high){
        return ;
    }
    int l = low;
    int r = high;
    int key = a[low];
    while(lwhile(a[r]>=key && lif(lwhile(a[l]<=key && lif(l1);
    qsort(a, l+1, high);
}
int main()
{
    int n;
    while(scanf("%d", &n)!=EOF)
    {
        for(int i=0; iscanf("%d", &a[i]);
        }
        qsort(a, 0, n-1);
        for(int i=0; i1; i++){
            printf("%d ", a[i]);
        }
        printf("%d", a[n-1]);
        printf("\n");
        memset(a, 0, sizeof(a));
    }
    return 0;
}

你可能感兴趣的:(sdnu1521手写qsort排序)