*快速排序的递归实现 */ # include <stdio.h> # define N 8 int Quick_sort_Partion(int R[],int left,int right) { int temp,buf; int i=left,j=right; while(left<right) { buf=R[left]; while(left<right&&buf<=R[right]) right--;
temp=R[right]; R[right]=R[left]; R[left]=temp; while(left<right&&buf>=R[left]) left++; if(left==right) return left; else{
temp=R[right]; R[right]=R[left]; R[left]=temp; }
}
}
void Quick_sort(int R[],int left,int right) { int temp; if(left<right){ temp=Quick_sort_partion(R,left,right); Quick_Sort(R,left,temp-1); Quick_Sort(R,temp+1,right);
}
}
int main(void){ int i; int X[N]={26,23,96,13,36,67,45,15}; Quick_Sort(X,0,7); for(i=0;i<8;i++) print ("%d",X[i]); printf("\n");
}
|