/*************************************** **************************
* Find the biggest X number in a sequence
* The basic method is the same as the quicksort
*
* 1. Move the smaller one before the cursor
* 2. Move the bigger one after the previous
* 3. determin whether the X matches the locale's index
* 3.1 If yreturn the index
* 3.2 If nrecursively call the func with proper Param
*
**************************************** *************************/
# Define CNT 10
# Include <stdio. h>
# Include <stdlib. h>
# Include <string. h>
# Include <time. h>
Int findbiggestx (int * pA, int low, int high, int key );
Int main (void)
{
Int arr [CNT];
Int I = 0;
Int key = 4;
Printf ("arr is: \ n ");
Srand (unsigned) Time (null); // use current time as seed
For (I = 0; I <CNT; I ++)
{
Arr [I] = rand () %100;
Printf ("% d \ t", arr [I]);
}
Printf ("\ n ");
Findbiggestx (ARR, 0, sizeof (ARR)/sizeof (INT)-1, key );
For (I = 0; I <CNT; I ++)
{
Printf ("% d \ t", arr [I]);
}
Printf ("\ n ");
For (I = 0; I <key; I ++)
{
Printf ("% d \ t", arr [I]);
}
Printf ("\ n ");
Getchar ();
Return 0;
}
Int findbiggestx (int * pA, int low, int high, int key)
{
Int Limit = pa [0];
Int low_temp = low;
Int high_temp = high;
While (low {
While (PA [High]> = running & low {
High --;
}
Pa [low] = pa [High];
While (PA [low] <= strong & low {
Low ++;
}
Pa [High] = pa [low];
}
Pa [low] = running;
If (key-1 = low)
{
Return low;
}
Else if (key-1 <low)
{
Return findbiggestx (Pa, low_temp, low, key );
}
Else
{
Return findbiggestx (Pa, low + 1, high_temp, key );
}
}