parent
7ec56895a3
commit
11176d83fa
@ -0,0 +1,18 @@
|
||||
def linear_Search(list1, n, key):
|
||||
|
||||
# Searching list1 sequentially
|
||||
for i in range(0, n):
|
||||
if (list1[i] == key):
|
||||
return i
|
||||
return -1
|
||||
|
||||
|
||||
list1 = [1 ,3, 5, 4, 7, 9]
|
||||
key = 7
|
||||
|
||||
n = len(list1)
|
||||
res = linear_Search(list1, n, key)
|
||||
if(res == -1):
|
||||
print("Element not found")
|
||||
else:
|
||||
print("Element found at index: ", res)
|
Loading…
Reference in new issue