forked from raamav/StandalonePrograms_Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSelectionSort.py
More file actions
38 lines (28 loc) · 705 Bytes
/
SelectionSort.py
File metadata and controls
38 lines (28 loc) · 705 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
#Implementing Selection Sort
#creating an unsorted list
import random as r
L1 = []
for i in range(1,20,2):
L1.append(i)
r.shuffle(L1) #note that this MUTATES the list
#Implementing Selection Sort
def sort_selection(L):
print(L)
n = len(L)
for i in range(n):
small = L[i]
print(small)
temp =0
s=0
for j in range(i+1,n):
#print("j ",j)
if L[j] < small:
temp = small #temp= 5
small = L[j] # small = 1
L[j] = temp
L[i] = small
s+=1
#print(small)
print(L)
#testing
sort_selection(L1)