我试图创建一个包含20个随机整数的表,并在python中实现表中的二进制搜索算法。你知道吗
这是我的密码:
def binary_search(a,key): #function with the binary search algorithm
imin=0
imax=le(a)-1
while (imax >= imin):
imid=midpoint(imin,imax);
if (a[imid]==key):
print(imid)
elif (a[imid]<key):
imin=imid+1;
else:
imax=imid-1;
print('KEY_NOT_FOUND')
randomlst=[] #a list for saving 20 random numbers
for i in range (20):
rng=random.randint(1,100)
randomlst.append(rng)
board=[randolst] # here i import the list into the board
n=int(input('Give the key')
binary_search(board,n)
我的问题是:
谢谢你的时间,请原谅我的英语。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐