I have an assingment. the assingment says to write two functions in python that will:
- Sort the the list using bubble Sort
- Take numerical input from the user and search the previously sorted list for that number.
My first function - sort
- can sort. However, my second function is not performing a binary search correctly. My end goal is to combine the two functions.
Here is my current code:
Bubble Sort
def sort(x):
for j in range(len(x)):
for i in range (len(x)-1):
if x[i]> x[i+1]:
temp =x[i]
x[i]=x[i+1]
x[i+1]=temp
return x
sl = sort([87,56,34,23,89,15,2,200,28,31])
print (sl)
Binary Search
def bs(t):
s = 0
e = len(t)-1
found = False
c = int(input("Enter"))
while (s<=e):
mid = (s+e)//2
if t[mid]==c:
found = True
elif c > t[mid]:
s = mid+1
else:
e = mid-1
return found
bs([1,2,3,4,5])