Skip to content

Commit fee52ff

Browse files
pallu2211techyminati
authored andcommitted
Added Bogo Sort
1 parent b7755e1 commit fee52ff

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎bogoSort.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import random
2+
3+
def bogoSort(a):
4+
n = len(a)
5+
while (is_sorted(a)== False):
6+
shuffle(a)
7+
8+
def is_sorted(a):
9+
n = len(a)
10+
for i in range(0, n-1):
11+
if (a[i] > a[i+1] ):
12+
return False
13+
return True
14+
15+
def shuffle(a):
16+
n = len(a)
17+
for i in range (0,n):
18+
r = random.randint(0,n-1)
19+
a[i], a[r] = a[r], a[i]
20+
21+
a = [3, 2, 4, 1, 0, 5]
22+
bogoSort(a)
23+
print("Sorted array :")
24+
for i in range(len(a)):
25+
print ("%d" %a[i]),

0 commit comments

Comments
 (0)