【原】顺序查找

优点:是对表中数据元素的存储没有要求。另外,对于线性链表,只能进行顺序查找。

缺点:当n很大时,平均查找长度较大,效率低。

 1 def sequaential_search(lis, key):
 2     length = len(lis)
 3     for i in range(length):
 4         if lis[i] == key:
 5             return i
 6         else:
 7             return False
 8  
 9 if __name__ == '__main__':
10     LIST = [1, 5, 8, 123, 22, 54, 7, 99, 300, 222]
11     result = sequential_search(LIST, 123)
原文地址:https://www.cnblogs.com/HYanqing/p/13914905.html