25
loading...
This website collects cookies to deliver better user experience
from random import randint
def shuffle(arr: list):
for i in range(len(arr)):
randomInt = randint(0, len(arr) - 1)
arr[randomInt], arr[i] = arr[i], arr[randomInt]
def isSorted(arr: list) -> bool:
for i in range(len(arr) - 1):
if arr[i] > arr[i + 1]:
return False
return True
def BogoSort(arr: list) -> list:
# while the array is not sorted
while not isSorted(arr):
shuffle(arr)
# if the array is sorted
return arr
from random import randint
def isSorted(arr: list) -> bool:
for i in range(len(arr) - 1):
if arr[i] > arr[i + 1]:
return False
return True
def shuffle(arr: list) :
for i in range(len(arr)):
randomInt = randint(0, len(arr) - 1)
arr[randomInt], arr[i] = arr[i], arr[randomInt]
def BogoSort(arr: list) -> list:
while not isSorted(arr):
shuffle(arr)
return arr