5-有序表顺序查找算法

# 算法时间复杂度O(N)
def orderedSequentialSearch(alist, item):
    pos = 0
    found = False
    stop = False
    while pos < len(alist) and not found and not stop:
        if alist[pos] == item:
            found = True
        else:
            if alist[pos] > item:
                stop = True
            else:
                pos += 1
    return found


testlist = [1, 32, 32, 23, 4, 6, 8, 32, 577, 34]
print(orderedSequentialSearch(testlist, 233))
print(orderedSequentialSearch(testlist, 577))
上一篇:排序算法


下一篇:4-无序表顺序查找算法