qsort为啥也没输出
什么书啊? 都不行?程序代码:
# include <stdio.h> void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } void qsort(int a[], int p, int r) { int q; while(p < r) { q = pat(a, p, r); qsort(a, p, q - 1); qsort(a, q + 1, r); } } int pat(int a[], int p, int r) { int x = a[p], i = p, j = r + 1; while(p < r) { while(a[++j] < x && i < r) ; while(a[--j] > x) ; if(i >= j) break; swap(&a[i], &a[j]); } a[p] = a[j]; a[j] = x; return j; } int main() { int i; int a[8] = {2, 5, 3, 65, 43, 53, 24, 8}; qsort(a, 0, 7); for (i=0; i<8; i++) printf("%d ", a[i]); printf("\n"); return 0; }