-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.py
More file actions
48 lines (41 loc) · 837 Bytes
/
SelectionSort.py
File metadata and controls
48 lines (41 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Name : Prashant Rawat
Date : 4/01/2023
'''
import random
#function to print list
def printer(ssc):
print(lst,'\n ',' '*(ssc),'^',sep='')
lst=[]
if input('Do you want to enter your own list (if yes enter yes) : ')==('yes' or 'Yes'):
for i in range(1,10):
lst.append(int(input(f'Enter {i} value : ')))
# making a random list
while len(lst)<9:
ran=random.randint(1,9)
if ran not in lst :
lst.append(ran)
print('List is : ',lst)
sorted = False
step=1
while not sorted:
sn=step-1
print('\n\nStep : ',step)
#shorting list
for i in range(0,8):
if lst[i+1]<lst[i] and lst[i+1]<lst[sn]:
sn=i+1
printer(sn)
a=lst[step-1]
lst[step-1]=lst[sn]
lst[sn]=a
i=1
print(lst)
sorted=True
#cheacking if the list is sorted
while i<len(lst) and sorted:
if lst[i]<lst[i-1]:
sorted=False
i+=1
step+=1
print(lst)