2023-09-16 17:28:03 -07:00
|
|
|
proc binSearch val . a[] res .
|
|
|
|
|
low = 1
|
|
|
|
|
high = len a[]
|
|
|
|
|
res = 0
|
|
|
|
|
while low <= high and res = 0
|
|
|
|
|
mid = (low + high) div 2
|
|
|
|
|
if a[mid] > val
|
|
|
|
|
high = mid - 1
|
|
|
|
|
elif a[mid] < val
|
|
|
|
|
low = mid + 1
|
|
|
|
|
else
|
|
|
|
|
res = mid
|
|
|
|
|
.
|
|
|
|
|
.
|
2023-07-01 11:58:00 -04:00
|
|
|
.
|
|
|
|
|
a[] = [ 2 4 6 8 9 ]
|
2023-09-16 17:28:03 -07:00
|
|
|
binSearch 8 a[] r
|
2023-07-01 11:58:00 -04:00
|
|
|
print r
|