@@ -363,10 +363,10 @@ def counting_sort(arr, event, aux):
363363'''
364364def is_sorted (arr , event ):
365365 for i in range (0 , arr .length () - 1 ):
366- if (arr .get (i ) > arr .get (i + 1 )):
367- return - 1
368366 if (event .is_set ()):
369367 return 0
368+ if (arr .get (i ) > arr .get (i + 1 )):
369+ return - 1
370370 return 1
371371
372372def shuffle (arr , event ):
@@ -389,6 +389,15 @@ def bogo_sort(arr, event, aux = None):
389389 if (num == 1 ):
390390 finish (arr )
391391
392+ def miracle_sort (arr , event , aux = None ):
393+ while True :
394+ status = is_sorted (arr , event )
395+ if status == 1 :
396+ finish (arr )
397+ return
398+ if status == 0 :
399+ return
400+
392401# Sorting Algorithm Input
393402class SA :
394403 ''' name = how it will appear on the dropdown menu
@@ -399,4 +408,4 @@ def __init__(self, name, sort):
399408 self .sort = sort
400409
401410sorting_algos = [SA ("Selection Sort" , selection_sort ), SA ("Insertion Sort" , insertion_sort ), SA ("Quick Sort" , quick_sort ), SA ("Merge Sort" , merge_sort ),
402- SA ("Heap Sort" , heap_sort ), SA ("Radix Sort" , radix_sort ), SA ("Counting Sort" , counting_sort ), SA ("Bogo Sort" , bogo_sort )]
411+ SA ("Heap Sort" , heap_sort ), SA ("Radix Sort" , radix_sort ), SA ("Counting Sort" , counting_sort ), SA ("Bogo Sort" , bogo_sort ), SA ( "Miracle Sort" , miracle_sort ) ]
0 commit comments