BINARY SEARCHING
Program
class binay_search
{
public static void main()
{
int a[]={234,235,236,237,238,239,240,241,242};
int s,li,mi,hi;
s=241;
li=0;
hi=a.length-1;
mi=(li+hi)/2;
while(li<=hi)
{
if(s==a[mi])
{
System.out.println("Index No of the num you input is : "+mi);
break;
}
if(a[mi]<s)
{
li=mi+1;
}
else
hi=mi- 1;
mi=(li+hi)/2;
}
}
}
0 Comments