算法之顺序查找法

'''这是一个顺序查找的算法题'''
ls1 = [165, 92, 283, 272, 38, 87, 520, 242, 549, 844]


def sx_find(ls, v):

    n = len(ls)

    for i in range(n):
        if ls[i] == v:
            return i

    return -1


print(sx_find(ls1, 594))
print(sx_find(ls1, 549))

猜你喜欢

转载自www.cnblogs.com/python99/p/12366485.html