kopia lustrzana https://github.com/animator/learn-python
Create Linear search.py
rodzic
33d752647f
commit
5421e75588
|
@ -0,0 +1,18 @@
|
||||||
|
def search(arr, N, x):
|
||||||
|
|
||||||
|
for i in range(0, N):
|
||||||
|
if (arr[i] == x):
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
arr = list(map(int,input("enter the array elements: ").split()))
|
||||||
|
x = int(input("enter the number to search: "))
|
||||||
|
N = len(arr)
|
||||||
|
|
||||||
|
result = search(arr, N, x)
|
||||||
|
if(result == -1):
|
||||||
|
print("Element is not present in array")
|
||||||
|
else:
|
||||||
|
print("Element is present at index", result)
|
Ładowanie…
Reference in New Issue