Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Algorithms/sorting/bogo-sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'''
###pseudocode###
while not Sorted(list) do
shuffle (list)
done
'''
import random
def bogoSort(lst):
while(is_sorted(lst) != True):
shuffle(lst)

def shuffle(lst):
for i in range(0, len(lst)):
r = random.randint(0, len(lst) - 1)
#shuffle
lst[i], lst[r] = lst[r], lst[i]

#check if array is sorted or not
def is_sorted(lst):
for i in range(0, len(lst)):
if(lst[i] > lst[i + 1]):
return False
return True