python 递归查找

def search(data,find_n):
"递归数据二分查找法"
if data.count(find_n) >= 1:
mid=(len(data) / 2)
print data
if mid >= 0:
if data[mid] > find_n:
search(data[:mid],find_n)
elif data[mid] < find_n:
search(data[mid:],find_n)
elif data[mid] == find_n:
print 'fund is data',data[mid]

else:
print "cannot found"
else:
print 'found data has not the list '
if __name__ == '__main__':
data=list(range(10))
search(data,9)

posted @ 2019-11-28 16:21  石榴心  阅读(851)  评论(0编辑  收藏  举报