#include
void swap(int *a, int *b) {
int temp = 0;
temp = *b;
*b = *a;
*a = temp;
}
int Rand(int low, int high) {
int size = high - low + 1;
return low + rand() % size;
}
int Partition(int a[],int start,int end,int length) {
int index = Rand(start, end);
swap(&a[index], &a[end]);
int small = start - 1;
for (index = start; index < end; ++index) {
if (a[index] < a[end]) {
++small;
if (small != index)
swap(&a[index], &a[small]);
}
}
++small;
swap(&a[small], &a[end]);
return small;
}
void Qsort(int a[], int length, int start, int end) {
if (start == end)
return;
int index = Partition(a, start, end, length);
if (index > start) {
Qsort(a, start, index - 1, length);
}
if (index < end) {
Qsort(a, index + 1, end, length);
}
}
void main() {
int a[] = { 7,6,44,8,2,3,1,9,6 };
Qsort(a, 9, 0, 8);
for (int j = 0; j < 9; j++) {
printf("%d ", a[j]);
}
你参数传错了 如下
void Qsort(int a[], int length, int start, int end) {
if (start == end)
return;
int index = Partition(a, start, end, length);
if (index > start) {
Qsort(a,length, start, index - 1);
}
if (index < end) {
Qsort(a, length,index + 1, end );
}
if (start = end)
return
改成== 要不直接退出了