void Util::bs30()
{
int arr[]={10,20,30,40,50,60,70,80,90,100};
int key=90;
int idx=binarySearch29(arr,0,9,key);
if(idx>-1)
{
cout<<"The key "<<key<<" found at "<<idx<<endl;
}
else
{
cout<<"The key "<<key<<" not found in array!"<<endl;
}
cout<<getTime()<<",finished in void Util::bs30()"<<endl;
}
int Util::binarySearch29(int arr[], int low, int high, int key)
{
if(low<=high)
{
int mid=low+(high-low)/2;
if(arr[mid]==key)
{
return mid;
}
else if(arr[mid]<key)
{
return binarySearch29(arr,mid+1,high,key);
}
else
{
return binarySearch29(arr,low,mid-1,key);
}
}
return -1;
}
void binarySearch14();
int main(int args, char **argv)
{
try
{
binarySearch14();
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
}
void binarySearch14()
{
Util ul;
ul.bs30();
}
![]()