4.在一个有序数组中,找某个数是否存在(二分法)
bool IsExistTarget(int arr[], int size, int target)
{
if (!arr) return false;
int Left = 0;
int Right = 0;
int Mid = 0;
while (Left < Right)
{
Mid = Left + ((Right-Left)>>1);
if (arr[Mid] == target)
{
return true;
}
else if (arr[mid] > target)
{
Right = mid - 1;
}
else
{
Left = mid + 1;
}
}
return target == arr[Left];
}