Divide and conquer the method to seek the median number

Source: Internet
Author: User

Other people's Reference
45967535
Your own algorithm.

Include

using namespace Std;
void Mid (int a[],int aleft,int aright,int b[],int bleft,int Bright)
{
Double mid;
int n=aright-aleft+1;
int k1= (aleft+aright)/2;
int k2= (bleft+bright)/2;
if (aright-aleft==1&&bright-bleft==1)
{

  cout<< "mid=" << (Max (A[aleft], B[bleft]) + min (A[aright], b[bright])/2.0<<endl; return;}    if ((aleft==aright) && (bleft==bright)) {mid= (A[aleft]+b[bleft])/2.0;    cout<< "Mid=" <<mid<<endl;    Return            }else{if (A[k1]==b[k2]) {MID=A[K1];                        cout<< "Mid=" <<mid<<endl;            } if (A[k1]<b[k2]) {Mid (A,K1,ARIGHT,B,BLEFT,K2); cout<< "Mid1 (A,K1,N-1,B,0,K2)" << "" <<k1<< "<<aright<<" "<<" "<<        bleft<< "" <<k2<<endl;            } if (A[k1]>b[k2]) {Mid (a,aleft,k1,b,k2,bright); cout<< "Mid2 (a,0,k1,b,k2,n-1)" << "" <<aleft<< "<<k1-1<<" "<<" "<<        k2<< "" <<bright<<endl; }}

}
int main ()
{
int A[]={1, 12, 15, 26, 38};
int b[]={13, 14, 40, 42, 45};
Mid (a,0,4,b,0,4);
System ("pause");
}

Divide and conquer the method to seek the median number

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.