Pure C language: Divide and conquer to find the minimum element of the K source code

Source: Internet
Author: User

# Include
 
  
Void fun (int array [], int low, int high) {int I = low; int j = high; int temp = array [I]; while (I <j) {while (array [j]> = temp) & (I <j) {j --; array [I] = array [j];} while (array [I] <= temp) & (I <j) {I ++; array [j] = array [I] ;}} array [I] = temp; if (I-1> low) {fun (array, low, I-1);} if (high> I + 1) {fun (array, j + 1, high) ;}else {return ;}} void main () {int array [10]; printf ("Enter ten digits to search for the k-th small element: \ n "); for (int I = 0; I <10; I ++) {printf (" Enter the % d count: ", I + 1 ); scanf ("% d", & array [I]);} fun (array,); int k; printf ("Enter the smallest elements to search :"); scanf ("% d", & k); printf ("this element is: % d", array [k-1]); printf ("\ n ");} 2 # include
  
   
# Include
   
    
Void interchange (int * m, int * n) {int temp = * m; * m = * n; * n = temp;} int partition (int array [], int p, int q) {int I, j; I = p; j = q + 1; while (1) {do I ++; while (array [I] array [p]) & (j! = P); if (I
    
     
> N; int * a = (int *) malloc (n * sizeof (int); for (I = 0; I
     
      
> A [I];} cout <
      
        I; if (I <= n) break; cout <"overflow! "<
       
        

Related Article

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.