编程语言
首页 > 编程语言> > 4-无序表顺序查找算法

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))

标签:testlist,3432,alist,无序,pos,sequentialSearch,算法,查找,found
来源: https://www.cnblogs.com/lotuslaw/p/13968776.html