-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbogoSortAlgorithm.py
More file actions
33 lines (24 loc) · 867 Bytes
/
Copy pathbogoSortAlgorithm.py
File metadata and controls
33 lines (24 loc) · 867 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
import random
import time
import sortingUtils
from sortingUtils import isSorted, wait
def bogoSort(array, delay):
startTime = time.perf_counter()
originalArray = array.copy()
while not isSorted(array) and sortingUtils.sorting:
sortingUtils.swaps += 1
random.shuffle(array)
sortingUtils.swapDataSound.play()
sortingUtils.comparedIndices.clear()
sortingUtils.sortTimeVisual = time.perf_counter() - startTime
wait(delay)
for i in range(len(array)):
if array[i] != originalArray[i]:
sortingUtils.comparedIndices.append(i)
yield
originalArray = array.copy()
def bogoSortNoVisible(array):
timeArray = array.copy()
while not isSorted(timeArray) and sortingUtils.sorting:
random.shuffle(array)
sortingUtils.sortTime = float('inf')