python s12 day4 算法基础之二分查找
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python s12 day4 算法基础之二分查找相关的知识,希望对你有一定的参考价值。
def binary_search(data_source,find_n):
mind=int(len(data_source)/2)
if len(data_source)>=1:
if data_source[mid]>find_n:
print("data in left of [%s]"%sdata_souerce[mid])
//print(data_souerce[:mid]
binary_search(data_source[:mid],find_n)
elif data_source[mid]<find_n:
print("data in right of [%s]"%data_souerce[mid])
//print(data_souerce[mid:]
binary_search(data_source[mid:],find_n)
else:
print("found find_s "data_souerce[mid])
binary_search(data_source[mid:],find_n)
else:
print("cannot find....")
if_name_==‘_main_‘:
data=list(range(1,600,3)
print(data)
binary_search(data,39)
以上是关于python s12 day4 算法基础之二分查找的主要内容,如果未能解决你的问题,请参考以下文章