线性查找
def linear_search(data_list, value):
for i in range(len(data_list)):
if data_list[i] == value:
return i
return '未找到'
data = list(range(200))
res = linear_search(data, 33)
print(res) # 找到了就会返回它的下标,data里第一个元素是0,下标也是0,如果没有找到就会打印未找到
def linear_search(data_list, value):
for i in range(len(data_list)):
if data_list[i] == value:
return i
return '未找到'
data = list(range(200))
res = linear_search(data, 33)
print(res) # 找到了就会返回它的下标,data里第一个元素是0,下标也是0,如果没有找到就会打印未找到