-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstalinSortAlgorithm.py
More file actions
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
import time
import sortingUtils
from sortingUtils import isSorted, wait
def stalinSort(array, delay):
i = 0
startTime = time.perf_counter()
while not isSorted(array):
while i < len(array) - 1:
sortingUtils.comparisons += 1
sortingUtils.comparedIndices.clear()
sortingUtils.selectedIndices.clear()
if array[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)
def stalinSortNoVisible(array):
i = 0
timeArray = array.copy()
startTime = time.perf_counter()
while i < len(timeArray) - 1:
if timeArray[i] > timeArray[i + 1]:
timeArray.pop(i + 1)
sortingUtils.sortTime = time.perf_counter() - startTime
else:
i += 1