Write Reverse algorithm for binary search.
The Reverse method reverses the order of the elements in an array.
BinarySearch(): performs a binary search on the list of elements.
Sort(): Sorts the items
Reverses items
int mid;
int first = 0;
int last = list.length(-) - 1;
while ( first <= last )
{
mid = (first + last)/2;
if ( list[mid] == target )
return mid;
if ( list[mid]>target )
last = mid - 1;
else
first = mid + 1;
}
return - 1;
}
Sorting :{
Intmain()
Intarray[] = {};
Int elements = sizeof(array);
Std::sort(array,array + elements);
For(int=0, i<<elements, i++)
Std::cout<<array[i]<<' ';
}
Reverse the array:
{
int n,c,t,end,array[];
for(c=0, c<n/2, c++)
{
t = array[c];
array[c] = array[end];
array[end] = t;
}
1 comments:
Attend The PMP Certification in Abu Dhabi From ExcelR. Practical PMP Certification in Abu Dhabi Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The PMP Certification in Abu Dhabi.
ReplyExcelR PMP Certification in Abu Dhabi
Post a Comment