We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 96eeb3d commit 7115be0Copy full SHA for 7115be0
Arrays-Sorting/src/BogoSort/BogoSort.py
@@ -0,0 +1,14 @@
1
+import random
2
+def shuffle(array):
3
+ for i in range(len(array)-1, -1, -1):
4
+ j = random.randint(0, i)
5
+ array[i], array[j] = array[j], array[i]
6
+def is_sorted(array):
7
+ for i in range(len(array) - 1):
8
+ if array[i] > array[i + 1]:
9
+ return False
10
+ return True
11
+def bogosort(array):
12
+ while not is_sorted(array):
13
+ shuffle(array)
14
+ return array
0 commit comments