Top9:数据结构-顺序查找-python
"""
@Time: 2020/9/1/001 10:46
@Author: Carl
@File: sequentialSearchDemo
@Software: PyCharm Professional Edition
"""
def sequentialSearch(alist, item):
pos = 0
found = False
while pos < len(alist) and not found:
if alist[pos] == item:
found = True
else:
pos = pos + 1
return found
testlist = [1, 2, 32, 8, 17, 19, 42, 13, 0]
print(sequentialSearch(testlist, 3))
print(sequentialSearch(testlist, 13))