22 lines
442 B
Python
22 lines
442 B
Python
nums = [6, 7, 8, 12, 19, 55, 90, 98];
|
|
|
|
searchItem = 55;
|
|
found = False;
|
|
|
|
start = 0;
|
|
end = len(nums);
|
|
mid = 0;
|
|
|
|
while (start <= end):
|
|
mid = int((start + end) / 2);
|
|
if nums[mid] == searchItem:
|
|
print(f'found {searchItem} at index {mid}');
|
|
found = True;
|
|
break;
|
|
elif nums[mid] > searchItem:
|
|
end = mid - 1;
|
|
else:
|
|
start = mid + 1
|
|
|
|
if not found:
|
|
print(f'{searchItem} was not found in nums'); |