- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionSortAlgorithm.py
More file actions
Latest commit
43 lines (35 loc) · 1.52 KB
/
Copy pathselectionSortAlgorithm.py
File metadata and controls
43 lines (35 loc) · 1.52 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
importtime
importsortingUtils
fromsortingUtilsimportisSorted, wait
defselectionSort(array, delay):
startTime=time.perf_counter()
whilenotisSorted(array) andsortingUtils.sorting:
foriinrange(len(array) -1):
minIdx=i
sortingUtils.selectedIndices.clear()
sortingUtils.comparedIndices.clear()
sortingUtils.selectedIndices.append(minIdx)
forjinrange(i+1, len(array)):
sortingUtils.comparisons+=1
ifarray[j] <array[minIdx]:
minIdx=j
sortingUtils.selectedIndices.append(minIdx)
sortingUtils.comparedIndices.append(i)
sortingUtils.swapDataSound.play()
sortingUtils.sortTimeVisual=time.perf_counter() -startTime
array[i], array[minIdx] =array[minIdx], array[i]
sortingUtils.swapDataSound.play()
sortingUtils.swaps+=1
wait(delay)
yield
defselectionSortNoVisible(array):
startTime=time.perf_counter()
timeArray=array.copy()
whilenotisSorted(timeArray) andsortingUtils.sorting:
foriinrange(len(timeArray) -1):
minIdx=i
forjinrange(i+1, len(timeArray)):
iftimeArray[j] <timeArray[minIdx]:
minIdx=j
timeArray[i], timeArray[minIdx] =timeArray[minIdx], timeArray[i]
sortingUtils.sortTime=time.perf_counter() -startTime