kopia lustrzana https://github.com/animator/learn-python
Create Sentinel Search.py
rodzic
5421e75588
commit
6cdedb1b58
|
@ -0,0 +1,22 @@
|
||||||
|
def sentinelSearch(arr, n, key):
|
||||||
|
|
||||||
|
last = arr[n - 1]
|
||||||
|
|
||||||
|
arr[n - 1] = key
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
while (arr[i] != key):
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
arr[n - 1] = last
|
||||||
|
|
||||||
|
if ((i < n - 1) or (arr[n - 1] == key)):
|
||||||
|
print(key, "is present at index", i)
|
||||||
|
else:
|
||||||
|
print("Element Not found")
|
||||||
|
|
||||||
|
arr = list(map(int,input("Enter the array elements: ").split()))
|
||||||
|
n = len(arr)
|
||||||
|
key = int(input("enter the number to search: "))
|
||||||
|
|
||||||
|
sentinelSearch(arr, n, key)
|
Ładowanie…
Reference in New Issue