-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionSort.py
More file actions
35 lines (27 loc) · 969 Bytes
/
selectionSort.py
File metadata and controls
35 lines (27 loc) · 969 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
import time
def selection(data, drawData, timeTick):
for i in range(0,len(data)):
min_pos=i
for j in range(i+1,len(data)):
if data[j]< data[min_pos]:
min_pos=j
drawData(data,getcolor(len(data),i,min_pos ,i))
time.sleep(timeTick)
data[min_pos],data[i]=data[i],data[min_pos]
drawData(data,getcolor(len(data),min_pos,i,i))
time.sleep(timeTick)
# drawData(
# data, ['green' if x <= i else 'white' for x in range(len(data))])
time.sleep(timeTick)
def getcolor(length,x,y,static):
colorArray=[]
for i in range(length):
if i==x:
colorArray.append('yellow')
elif i==y:
colorArray.append('pink')
elif i < static:
colorArray.append('green')
else:
colorArray.append('white')
return colorArray