#include "iostream"
void quicksort(int data[],int left,int right);
int main()
{
int number=9;
int data[]={5,6,4,8,2,3,7,9,1};
int i;
for (i=0;i<number;i++){
printf("%d",data[i]);
}
printf("\n");
quicksort(data,0,number-1);
printf("\n");
for (i=0;i<number;i++){
printf("%d",data[i]);
}
printf("\n");
system("PAUSE");
return 0;
}
void quicksort(int data[],int left,int right){
int i=left+1;
int j=right;
int splitting=data[left];
int temp;
if (left<right){
do{
while(i<right && data[i]<splitting)i++;
while(j>left && data[j]>splitting)j--;
if (i<j){
temp=data[i];
data[i]=data[j];
data[j]=temp;
}
}while(i<j);
temp=data[left];
data[left]=data[j];
data[j]=temp;
quicksort(data,left,j-1);
quicksort(data,j+1,right);
}
}
沒有留言:
張貼留言