I am trying to execute a Binary search to find an element in a circularly sorted array. I get a type error that I don't seem to understand. Any suggestions/modifications will be appreciated.
here is my code:
def Binarysearch(a, low, high, x):
if low > high:
return -1
else:
mid = (low + high)/2
if x == a[mid]:
return mid
elif a[mid] <= a[high]:
if x > a[mid] and x <= a[high]:
return Binarysearch(a, mid+1, high, x)
elif a[mid] >= a[low]:
if x >= a[low] and x < a[mid]:
return Binarysearch(a, low, mid-1, x)
elem_list = [6, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5]
x = int(raw_input('enter search elemet'))
lenlist = len(elem_list)
result = Binarysearch(elem_list, 0, lenlist-1, x)
if result == -1:
print "Not found"
else:
print "Found it", elem_list[result]
I get error:
Line32: TypeError: list indices must be integers, not NoneType