python-线性查找

tech2024-12-08  7

def linear_search(L, e): found = False for i in range(len(L)): # go through all elements if e == L[i]: found = True break # with a break to stop loop while found, Complexity O(n) return found L =[1, 2, 3, 5, 6, 4] e = 7 linear_search(L, e)
最新回复(0)