#include<iostream> #include<cstdio> using namespace std; int a[10]; int part(int a[],int low,int high) { int temp=a[low]; while(low<high) { while(low<high&&a[high]>=temp) high--; a[low]=a[high]; while(low<high&&a[low]<=temp) low++; a[high]=a[low]; } a[low]=temp; return low; } void quicksort(int a[],int low,int high) { if(low<high) { int pivot=part(a,low,high); quicksort(a,low,pivot-1); quicksort(a,pivot+1,high); } } int main() { for(int i=0;i<10;i++) cin>>a[i]; quicksort(a,0,9); for(int i=0;i<10;i++) cout<<a[i]<<endl; } |
Double click to view unformatted code.