Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search clement not
Advertisements
प्रश्न
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found” using Binary search technique.
5.6, 11.5, 20.8, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
थोडक्यात उत्तर
Advertisements
उत्तर
class binary
{
double x[]={5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5};
double n;
binary(double z)
{
n=z
}
void search()
{
int f=0, 1=x.length,m;
while(f<=1)
{
m=(f+1)/2;
if(x[m]==n)
{
System.out.println("Search Successful");
System.exit(0);
}
if(x[m]<n)f=m+1;
if(x[m]>n)1=m-1;
}
System.out.println("Search Unsuccessful");
}
}shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
