• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. sortList = [1,4,4,5,6,7,8,8.5,8.6,9,11,133]
2. value = 1
3. def binSearch(value,myList):
4.     left = 0
5.     right = len(myList) - 1
6.     found = False
7.     mid = int((left + right)/2)
8.     while value != myList[mid]:
9.         mid = int((left + right)/2)
10.         if myList[mid] > value:
11.             right = mid
12.         elif myList[mid] < value:
13.             left = mid
14.         mid = int((left + right)/2)
15.         if left == mid:
16.             found=False
17.             pnt1 = value - myList[mid]
18.             pnt2 = myList[mid+1] - value
19.             if pnt2 < pnt1:
20.                 mid += 1
21.             return mid,found
22.         elif value == myList[mid]:
23.             while value == myList[mid+1]:
24.                 mid += 1
25.                 found = True
26.     found = True
27.     return mid,found