Commit 48938f44 by BellCodeEditor

save project

parent 1d6ef081
Showing with 2 additions and 3 deletions
...@@ -4,7 +4,7 @@ for i in range(int(input("有几个数字"))): ...@@ -4,7 +4,7 @@ for i in range(int(input("有几个数字"))):
a=int(input("数字:")) a=int(input("数字:"))
low=0 low=0
high=len(num_list)-1 high=len(num_list)-1
for i in range(30): for i in range(high):
mid=(low+high)//2 mid=(low+high)//2
if a==num_list[mid]: if a==num_list[mid]:
print("找到了!索引是"+str(mid)) print("找到了!索引是"+str(mid))
...@@ -12,4 +12,4 @@ for i in range(int(input("有几个数字"))): ...@@ -12,4 +12,4 @@ for i in range(int(input("有几个数字"))):
elif a<num_list[mid]: elif a<num_list[mid]:
high=mid-1 high=mid-1
elif a>num_list[mid]: elif a>num_list[mid]:
low=mid+1 low=mid+1
\ No newline at end of file
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