Skip to content

Commit 711d722

Browse files
committed
added test_skill in bab 8
1 parent 8bab946 commit 711d722

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Insertion sort, created by github @adnanhf
2+
3+
def insertionSort(list):
4+
for i in range(len(list)):
5+
x, j = list[i], i - 1
6+
while j >= 0 and list[j] < x:
7+
list[j + 1] = list[j]
8+
j = j - 1
9+
list[j + 1] = x
10+
11+
12+
def sequentialSearch(list, item):
13+
pos = 0
14+
found = False
15+
16+
while pos < len(list) and not found:
17+
if list[pos] == item:
18+
found = True
19+
else:
20+
pos += 1
21+
if found:
22+
print('the number you are looking for is at %s' % (pos + 1))
23+
else:
24+
print('the number you are looking for is not found!')
25+
26+
27+
if __name__ == '__main__':
28+
thelist, n = [], int(input('Input the amount of list elements : '))
29+
for i in range(n):
30+
element = int(input('Input the %s elements : ' % (i + 1)))
31+
thelist.append(element)
32+
insertionSort(thelist)
33+
find = int(input('Input the number you want to search: '))
34+
print(thelist)
35+
sequentialSearch(thelist, find)

0 commit comments

Comments
 (0)