- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbogoSortAlgorithm.py
More file actions
Latest commit
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
importrandom
importtime
importsortingUtils
fromsortingUtilsimportisSorted, wait
defbogoSort(array, delay):
startTime=time.perf_counter()
originalArray=array.copy()
whilenotisSorted(array) andsortingUtils.sorting:
sortingUtils.swaps+=1
random.shuffle(array)
sortingUtils.swapDataSound.play()
sortingUtils.comparedIndices.clear()
sortingUtils.sortTimeVisual=time.perf_counter() -startTime
wait(delay)
foriinrange(len(array)):
ifarray[i] !=originalArray[i]:
sortingUtils.comparedIndices.append(i)
yield
originalArray=array.copy()
defbogoSortNoVisible(array):
timeArray=array.copy()
whilenotisSorted(timeArray) andsortingUtils.sorting:
random.shuffle(array)
sortingUtils.sortTime=float('inf')