به وبلاگم خوش آمدید

کپی برداری از مطالب وبلاگ فقط با ذکر منبع (azarprogrammer.blog.ir)

به وبلاگم خوش آمدید

کپی برداری از مطالب وبلاگ فقط با ذکر منبع (azarprogrammer.blog.ir)

جستجوی دودویی (binary search)

چهارشنبه, ۲۶ آذر ۱۳۹۳، ۱۰:۴۲ ب.ظ
//azarprogrammer.blog.ir
#include<iostream>
#include<conio.h>
using namespace std;
void binsearch(int x,int s[])
{
int low=1,high=20,location=0,mid;
while(low<=high&&location==0)
{
mid=(low+high)/2;
if(x==s[mid])
location=mid;
else if(x<s[mid])
high=mid-1;
else
low=mid+1;
}
cout<<"The place is :"<<location+1;
}
int main()//azarprogrammer.blog.ir
{
int i,x,s[20];
cout<<"Enter the 20-digit order"<<endl;
for(i=0;i<20;i++)
{
cout<<"number "<<i+1<<" :";
cin>>s[i];
}
cout<<"Enter the number Search"<<endl;
cin>>x;
binsearch(x,s);
getch();
return 0;
}
//azarprogrammer.blog.ir
موافقین ۰ مخالفین ۰ ۹۳/۰۹/۲۶
سجاد بوزکند

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی