##二分查找法 def binary_search(data, find_n): if len(data) >= 1: mid = int(len(data) / 2) if find_n < data[mid]: binary_search(data[:mid], find_n) elif fin ...
##二分查找法
def binary_search(data, find_n):
if len(data) >= 1:
mid = int(len(data) / 2)
if find_n < data[mid]:
binary_search(data[:mid], find_n)
elif find_n > data[mid]:
binary_search(data[mid+1:], find_n)
else:
print('find the number:', data[mid])
else:
print('cant find the number...')
##冒泡排序
def mppx(data):
for i in range( len(data) - 1 ):
for j in range( len(data) - 1 - i ):
if data[j] > data[i]:
data[i], data[j] = data[j], data[i]
##選擇演算法
def xzpx(data):
for i in range( len(data) - 1 ):
k = i
for j in range( i+1, len(data)-1):
if data[j] < data[k]:
k = j
data[i], data[k] = data[k], data[i]