#include <stdio.h> |
int assign( int arr[], int down, int up) { |
int q=down; |
int u; |
int t; |
for (u=down;u<up;u++) |
//arr[q]与arr[u]互换,q前移,否则u前移 |
if (arr[u]<=arr[up]) { |
int t=arr[q]; |
arr[q]=arr[u]; |
arr[u]=t; |
q++; |
} |
} |
|
void quick_sort( int arr[], int down, int up) { |
int pos; |
if (down>=up) //不处理 |
return ; |
pos=assign(arr,down,up); //调用assign方法找到中间值pos |
quick_sort(arr,down,pos-1); //调用sort_sort方法对pos前面的数据排序 |
quick_sort(arr,pos+1,up); //调用sort_sort方法对pos后面的数据排序 |
} |
void main() |
{ |
int a[]={23,13,49,6,31,19,28}; |
int down = 0; |
int up =6; |
int i; |
quick_sort(a,down,up); |
for ( i=0;i<=up;i++) |
printf ( "%4d" ,a[i]); |
return 0; |
} |