From 19f0dbb8556c91ff454c435e68695956881a91d9 Mon Sep 17 00:00:00 2001 From: LAPTOP-DA9J2RNJ Date: Wed, 12 Oct 2022 22:36:14 +0530 Subject: [PATCH] Added Sentinel Search --- SEARCHING/py/sentinelSearch.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SEARCHING/py/sentinelSearch.py diff --git a/SEARCHING/py/sentinelSearch.py b/SEARCHING/py/sentinelSearch.py new file mode 100644 index 0000000..226628a --- /dev/null +++ b/SEARCHING/py/sentinelSearch.py @@ -0,0 +1,25 @@ +List = [] + +def entry(): + global num + num=int(input("Enter len of list")) + for i in range(num): + rollno=int(input("Enter values")) + List.append(rollno) + print(List) + + +def sentinelSearch(): + x= int(input("enter search element")) + temp = List[num-1] + List[num-1]=x + i=0 + for j in range(num): + if List[i]!=x: + i+=1 + + List[num-1]=temp + if (i< num-1 or temp==x): + print("Element found, index: ",i) + + \ No newline at end of file