Queries the minimum first n items in an array.

Source: Internet
Author: User


/*************************************** **************************
* 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 );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.