-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.py
More file actions
49 lines (34 loc) · 1.19 KB
/
SelectionSort.py
File metadata and controls
49 lines (34 loc) · 1.19 KB
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
49
# class based
class SelectionSort():
listints = []
def SelectionSort(self, x):
self.listints = x
end = len(self.listints)
for inta in range (0,end):
minv = inta
for intb in range (inta+1,end):
if self.listints[intb] < self.listints[minv]:
minv = intb
self.swap(inta, minv)
print (str(self.listints))
def swap(self, oldmin, newmin):
temphold = self.listints[oldmin]
self.listints[oldmin] = self.listints[newmin]
self.listints[newmin] = temphold
if __name__=="__main__":
A = SelectionSort()
A.SelectionSort([21,3,7,12,19,4,3,5])
# code based
def SelectionSort(x):
listints = x
end = len(listints)
for inta in range (0,end):
minv = inta
for intb in range (inta+1,end):
if listints[intb] < listints[minv]:
minv = intb
temphold = listints[inta]
listints[inta] = listints[minv]
listints[minv] = temphold
print (str(listints))
SelectionSort([21,3,7,12,19,4,3,5])