无序表的查找算法

 

def sequential_search(lis, key):
    length = len(lis)
    for i in range(length):
        if lis[i] == key:
            return i
    return False

LIST = [1, 5, 8, 123, 22, 54, 7, 99, 300, 222]
result = sequential_search(LIST, 123)
print(result)

如果查找到123就会打印出123 的位置索引,否则显示false

转载于:https://www.cnblogs.com/sea-stream/p/9801641.html

你可能感兴趣的:(无序表的查找算法)