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))
上一篇:5-有序表顺序查找算法


下一篇:冒泡排序