Skip to content

Commit 7115be0

Browse files
adding bogo sort
1 parent 96eeb3d commit 7115be0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)