Skip to content

Commit 5db8309

Browse files
Linear Search
1 parent b1b4bda commit 5db8309

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Diff for: LinearSearch.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
def search_linear(x,y):
2+
n = len( x )
3+
for i in range(n):
4+
if theValue[i] == y:
5+
return True
6+
return false
7+
8+
def sequentialSearch(alist, item):
9+
pos = 0
10+
found = False
11+
12+
while pos < len(alist) and not found:
13+
14+
if alist[pos] == item:
15+
found = True
16+
print("Found")
17+
else:
18+
pos = pos+1
19+
if found == False:
20+
print("Not found")
21+
return found
22+
23+
print("Enter numbers seprated by space")
24+
s = input()
25+
numbers = list(map(int, s.split()))
26+
trgt =int( input('enter a single number to be found in the list '))
27+
sequentialSearch(numbers, trgt)
28+

0 commit comments

Comments
 (0)