File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments