.Write a 'Divide and Conquer' algorithm to sort 'n' numbers in descending order.
Answers
Answered by
0
Explanation:
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int low, int high)
{
if(high >= low)
{
int mid = (low + high)/2;
if(mid == arr[mid])
return mid;
if(mid > arr[mid])
return binarySearch(arr, (mid + 1), high);
else
return binarySearch(arr, low, (mid -1));
}
return -1;
}
int main()
{
int arr[100000],i,n,k;
cout<<"Enter no of distinct elements in the array : ";
cin>>n;
cout<<"Enter the elements in ascending order"<<endl;
for(i=0;i<n;i++)
cin>>arr[i];
k=binarySearch(arr,0,n);
cout<<k<<" // ar["<<k<<"] = "<<k<<endl;
return 0;
}
Similar questions
Hindi,
1 month ago
Science,
1 month ago
Business Studies,
3 months ago
Math,
10 months ago
English,
10 months ago