"binary sort c++" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "binary sort c++" answered properly. Developers are finding an appropriate answer about binary sort c++ related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like binary sort c++. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on binary sort c++.
binary sort c++
int binarySearch(int a[], int item, int low, int high)
{
if (high <= low)
return (item > a[low]) ?
(low + 1) : low;
int mid = (low + high) / 2;
if (item == a[mid])
return mid + 1;
if (item > a[mid])
return binarySearch(a, item,
mid + 1, high);
return binarySearch(a, item, low,
mid - 1);
}
binary search in c++
#include<iostream>
using namespace std;
int binarySearch(int arr[], int p, int r, int num) {
if (p <= r) {
int mid = (p + r)/2;
if (arr[mid] == num)
return mid ;
if (arr[mid] > num)
return binarySearch(arr, p, mid-1, num);
if (arr[mid] < num)
return binarySearch(arr, mid+1, r, num);
}
return -1;
}
int main(void) {
int arr[] = {1, 3, 7, 15, 18, 20, 25, 33, 36, 40};
int n = sizeof(arr)/ sizeof(arr[0]);
int num = 33;
int index = binarySearch (arr, 0, n-1, num);
if(index == -1)
cout<< num <<" is not present in the array";
else
cout<< num <<" is present at index "<< index <<" in the array";
return 0;
}
All those coders who are working on the C++ based application and are stuck on binary sort c++ can get a collection of related answers to their query. Programmers need to enter their query on binary sort c++ related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about binary sort c++ for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of binary sort c++ while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "binary sort c++". Visit this developer's friendly online web community, CodeProZone, and get your queries like binary sort c++ resolved professionally and stay updated to the latest C++ updates.