Skip to content

Commit bf619d9

Browse files
authored
Remove use of sorted()
Replaced with custom is_sorted()
1 parent 2a55aa2 commit bf619d9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sorts/bozo_sort.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ def bozo_sort(array: list) -> list:
2727
>>> bozo_sort([8, 16, 0, 4, 10])
2828
[0, 4, 8, 10, 16]
2929
"""
30-
31-
while array != sorted(array):
30+
31+
def is_sorted(array):
32+
for i, n in enumerate(array):
33+
if i < len(array) - 1 and n > array[i + 1]:
34+
return False
35+
return True
36+
37+
while not is_sorted(array):
3238
index_a = random.randint(0, len(array) - 1)
3339
index_b = random.randint(0, len(array) - 1)
3440

0 commit comments

Comments
 (0)