- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstalinSortAlgorithm.py
More file actions
Latest commit
34 lines (31 loc) · 1.05 KB
/
Copy pathstalinSortAlgorithm.py
File metadata and controls
34 lines (31 loc) · 1.05 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
importtime
importsortingUtils
fromsortingUtilsimportisSorted, wait
defstalinSort(array, delay):
i=0
startTime=time.perf_counter()
whilenotisSorted(array):
whilei<len(array) -1:
sortingUtils.comparisons+=1
sortingUtils.comparedIndices.clear()
sortingUtils.selectedIndices.clear()
ifarray[i] >array[i+1]:
sortingUtils.comparedIndices.append(i+1)
sortingUtils.selectedIndices.append(i)
array.pop(i+1)
sortingUtils.swapDataSound.play()
sortingUtils.sortTimeVisual=time.perf_counter() -startTime
yield
else:
i+=1
wait(delay)
defstalinSortNoVisible(array):
i=0
timeArray=array.copy()
startTime=time.perf_counter()
whilei<len(timeArray) -1:
iftimeArray[i] >timeArray[i+1]:
timeArray.pop(i+1)
sortingUtils.sortTime=time.perf_counter() -startTime
else:
i+=1