HackToHell. Powered by Blogger.

Binary Search using functions

class bin{
public void fg(int a[],int y){
int f=0,l=a.length-1;
int mid=0;
while(f<=l){
mid=(f+l)/2;
if(m[mid] <s)
f=mid+1;
if(m[mid]>s)
l=mid-1;
if(m[mid] == s){
k=1;
break;
}
}
if( k == 1)
System.out.println("Found");
else
System.out.println("Not Found");
}
public static void main(String args[]){
int a[]={1,2,3,4,5,6,7,8,9,10};
bin j = new bin();
j.fg(a,6);
}
}

 

As usual compile as javac bin.java

run as java bin

Share on Google Plus

About hacktohell

Love technology.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment