Binary Find Insert

Source: Internet
Author: User

Inserted classics:

#include <stdio.h>
#define N 1000
int main ()
{
void Bi_search (int a[],int n,int x);
int a[n],i,m,x;
printf ("Please input the length:");
scanf ("%d", &m);
printf ("Please input a[0]:\n");
scanf ("%d", &a[0]);
I=1;
while (I<M)
{
scanf ("%d", &a[i]);
if (A[i]>=a[i-1])
i=i+1;
else printf ("Enter this number again:\n");

}
for (i=0;i<m;i++) printf ("%d \ n", A[i]);
printf ("Please input the num want search:\n");
scanf ("%d", &x);
Bi_search (A,M,X);
return 0;
}
void Bi_search (int a[],int n,int x)
{
int bot=0,top=n-1,mid,find=0,i,j,t1,t2;
Do
{

Mid= (Top+bot)/2;
if (a[mid]==x)
find=1;
else if (a[mid]>x)
Top=mid-1;
Else
bot=mid+1;
}while (Find==0&&bot<=top);
if (find==0)
{
printf ("No search\n");
if (X>a[n-1])
{a[n]=x;
for (i=0;i<=n;i++)
printf ("%d", A[i]);}

Else
{
for (i=0;i<n;i++)
{
if (a[i]>x)
{
T1=a[i];
A[i]=x;
for (j=i+1;j<n+1;j++)
{
T2=A[J];
A[J]=T1;
T1=t2;
}
for (i=0;i<n+1;i++)
printf ("%d", a[i]);
Break
}
}
}
}
else if (find==1)
printf ("It is the%dst number\n", mid);

}

Binary Find Insert

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.