-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSorter.py
More file actions
29 lines (20 loc) · 832 Bytes
/
SelectionSorter.py
File metadata and controls
29 lines (20 loc) · 832 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
from Sorter import Sorter
from Colors import *
class SelectionSorter(Sorter):
# data: data to be sorted
def sort(self, data):
length = data.size
for i in range(length):
min_index = i
for j in range(i+1, length):
data.my_list[j].set_color(RED)
self.force_update()
if data.my_list[min_index].height > data.my_list[j].height:
data.my_list[min_index].set_color(WHITE)
min_index = j
data.my_list[min_index].set_color(GREEN)
else:
data.my_list[j].set_color(WHITE)
data.my_list[i], data.my_list[min_index] = data.my_list[min_index], data.my_list[i]
data.my_list[i].set_color(WHITE)
self.force_update()