#include <iostream>

using namespace std;

void Quicksort(int *a,int low,int high)
{
    if(low>high)
    {
        return;
    }
    int i=low;
    int j=high;
    int key=a[i];
    while(i<j)
    {
        while(i<j&&a[j]>=key)
        {
            j--;
        }
        a[i]=a[j];
        while(i<j&&a[i]<=key)
        {
            i++;
        }
        a[j]=a[i];
    }
    a[i]=key;
    Quicksort(a,low,i-1);
    Quicksort(a,i+1,high);
}

int main()
{
    int n=5;
    int a[10];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    Quicksort(a,0,n);
    for(int j=0;j<n;j++)
    {
        cout<<a[j]<<" ";
    }
    return 0;
}

 

 posted on 2015-10-05 15:57  Oneface  阅读(252)  评论(0编辑  收藏  举报