4-无序表顺序查找算法

# 算法时间复杂度O(N)

def sequentialSearch(alist, item):
    pos = 0
    found = False
    while pos < len(alist) and not found:
        if alist[pos] == item:
            found = True
        else:
            pos += 1
    return found


testlist = [1, 2, 34, 23, 322, 3432, 343, 2, 0, 34]
print(sequentialSearch(testlist, 7))
print(sequentialSearch(testlist, 3432))
原文地址:https://www.cnblogs.com/lotuslaw/p/13968776.html