int partition( int a[], int l, int r ) { int i = l-1, j = r, v = a[r]; int tmp; for ( ; ; ) { while ( a[++i] < v ) ; while ( v < a[--j] ) if ( j == l ) break; if ( i >= j ) break; swap( a[i], a[j]) } swap( a[i], a[r] ); return i; } void quickSort( int a[], int l, int r ) { int mid; //获取的哨兵元素的下标 if (r <= l) return ; mid = partition( a, l, r ); quickSort( a, l, mid-1 ); quickSort( a, mid+1, r ); }