Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

6. Implement a sequential search

 def sequential_Search(list1, n, key):

for i in range(0, n):

if (list1[i] == key):

return i

return -1

list1 = [1 ,3, 5, 4, 7, 9]

key = 9

n = len(list1)

res = sequential_Search(list1, n, key)

if(res == -1):

print("Element not found")

else:

print("Element found at index: ", res)

Post a Comment

0 Comments