Skip to content

Commit e44a71a

Browse files
committed
Add front and back search
1 parent dbece37 commit e44a71a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def front_and_back_search(lst, item):
2+
'''
3+
args:
4+
lst: an unsorted array of integers
5+
item: data to be found
6+
7+
return:
8+
item which is found else False
9+
'''
10+
rear=0
11+
front=len(lst)-1
12+
u=None
13+
if rear>front:
14+
return False
15+
else:
16+
while rear<=front:
17+
if item==lst[rear] or item==lst[front]:
18+
u=''
19+
return True ##item found
20+
elif item!=lst[rear] and item!=lst[front]:
21+
if item > lst[rear]:
22+
rear=rear+1
23+
elif item < lst[front]:
24+
front=front-1
25+
if u==None:
26+
return False

0 commit comments

Comments
 (0)