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.
2 parents cc97f30 + 14a350f commit ce07bcfCopy full SHA for ce07bcf
Sorting Algorithms/bogosort.py
@@ -0,0 +1,36 @@
1
+import random
2
+
3
+# Sorts array a[0..n-1] using Bogo sort
4
5
6
+def bogo_sort(a):
7
+ n = len(a)
8
+ while (is_sorted(a) == False):
9
+ shuffle(a)
10
11
+# To check if array is sorted or not
12
13
14
+def is_sorted(a):
15
16
+ for i in range(0, n - 1):
17
+ if (a[i] > a[i + 1]):
18
+ return False
19
+ return True
20
21
+# To generate permuatation of the array
22
23
24
+def shuffle(a):
25
26
+ for i in range(0, n):
27
+ r = random.randint(0, n - 1)
28
+ a[i], a[r] = a[r], a[i]
29
30
31
+# Driver code to test above
32
+a = [3, 2, 4, 1, 0, 5]
33
+bogo_sort(a)
34
+print("Sorted array :")
35
+for i in range(len(a)):
36
+ print("%d" % a[i]),
0 commit comments