#include<stdio.h>
#define N 10
void quicksort (int a[],int low,int high);
int split (int a[],int low,int high);
int main (void){
int a[N],i;
printf("entr %d items to be sorted:",N);
for(i=0;i<N;i++)
scanf("%d",&a[i]);
quicksort(a,0,N-1);
printf("the sorted items are:");
for(i=0;i<N;i++)
printf("%d ",a[i]);
return 0;
}
int split(int a[],int low,int high){
int w=a[low];
for(;;){
while(low<high&&w<=a[high])high--;
if(low>=high)break;
a[low++]=a[high];
while(low<high&&w>=a[low])low++;
if(low>=high)break;
a[high--]=a[low];
}
a[high]=w;
return high;
}
void quicksort (int a[],int low,int high){
int middle;
if(low>=high)return;
middle=split(a,low,high);
quicksort(a,low,middle-1);
quicksort(a,middle-1,high);
}
uj5u.com熱心網友回復:
陣列宣告時,N沒有值是變數,你又不用動態陣列轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/117250.html
標籤:基礎類
上一篇:c++ builder opc
下一篇:cocos2dx 銷毀資源問題
