Commit 58830b72 by BellCodeEditor

auto save

parent d0e40e81
Showing with 21 additions and 12 deletions
import time
a=time.time()
alist = [88, 75, 72, 82, 90, 85, 78, 91]
n=len(alist)
for i in range (0,n-1):
for j in range(0,n-1-i):
if alist[j]>alist[j+1]:
alist[j],alist[j+1]=alist[j+1],alist[j]
print(alist)
b=time.time()
s=b-a
print(s)
a=[1,3,8,15,11,17,5,20,21,18]
b=len[a]
for i in range(0,b-1):
for j in range(0,b-1):
if a[j]>a[j+1]:
a[j],a[j+1]=a[j+1],a[j]
print(a)
def binary_search(alist,num):
low=0
high=len(alist)-1
mid=(low+high)//2
while low<=high:
if alist[mid]==num:
return mid
break
elif num<alist[mid]:
high=mid-1
else:
low=mid+1
mid=(low+high)//2
return None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment