首页 > 代码库 > python s12 day4 算法基础之二分查找

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=http://www.mamicode.com/list(range(1,600,3)

  print(data)

  binary_search(data,39)

python s12 day4 算法基础之二分查找