I am trying to search a descending sorted array using this binary search code. However, after I sort it, and try to search, it doesn\'t come back with any result, just a loading
This is one correct :
if
target< mynumbers[mid]
then you have to take last to mid-1, because we have to search in lower range i.e. first to mid-1
while (first<=last)
{
mid = (first + last) / 2;
if (target == mynumbers[mid])
Label11.Text = "Target " + item + " was found at index " + mynumbers[mid];
else if (target < mynumbers[mid])
last = mid - 1;
else (target > mynumbers[mid])
first = mid + 1;
}