#include<stdio.h> void find_bigger_num(int *arr ,int iLeft ,int iRight ,int iTargetSize ){ if( iLeft>= iRight) return; int iPivot = arr[ iLeft]; int iBegin = iLeft; int iEnd = iRight; while (iBegin < iEnd) { while (iBegin < iEnd && arr[iEnd] >= iPivot) { iEnd--; } arr[iBegin] = arr[iEnd]; while (iBegin < iEnd && arr[iBegin] <= iPivot) { iBegin++; } arr[iEnd] = arr[iBegin]; } arr[iBegin] = iPivot; //iBegin == iEnd int iLeftPartNum = iBegin - iLeft; if(iLeftPartNum== iTargetSize || iLeftPartNum+1==iTargetSize ) return; else if(iLeftPartNum> iTargetSize){ find_bigger_num( arr, iLeft,iBegin-1, iTargetSize); } else if(iLeftPartNum+1< iTargetSize){ find_bigger_num( arr,iBegin+1, iRight, iTargetSize-(iLeftPartNum+1)); } } int main() { int arr[] = {6,1,5,2,3,7,4,10,9,8}; int iTargetSize = 6; find_bigger_num(arr,0, sizeof(arr)/ sizeof( int)-1,iTargetSize); for ( int iLoop = 0; iLoop < iTargetSize; iLoop++) { printf( "%d ",arr[iLoop]); } printf( "\n"); return 0; }