Skip to content

Commit 8d861e8

Browse files
committed
added bogo sort
1 parent 8f7e19d commit 8d861e8

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

README.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@ please feel free to add and edit
44

55
## These have been added:
66

7-
* bubble sort
8-
* counting sort
9-
* quick sort
10-
* radix sort
11-
* insertion sort
12-
* selection sort
7+
* Bubble sort
8+
* Counting sort
9+
* Quick sort
10+
* Radix sort
11+
* Insertion sort
12+
* Selection sort
13+
* Bogo sort
1314

1415
## These will be added:
1516

16-
* pancake sort
17+
* Pancake sort
1718
* merge sort
18-
* insertion sort
19-
* bogo sort
20-
* pigeonhole sort
21-
* tim sort
22-
* heap sort
23-
* pancake sort
24-
* sudo bogo sort
19+
* Pigeonhole sort
20+
* Tim sort
21+
* Heap sort
22+
* Sudo bogo sort

sort.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import math
77

88
array = []
9-
size = 3
9+
size = 10
1010
count =[0]
1111
out =[0]
1212
rng = 10
@@ -148,7 +148,29 @@ def select():
148148

149149
#bogo sort
150150
def bogo():
151-
pass
151+
# WARNING this can take a LONG time only run with fewer than 10 items to sort
152+
global array
153+
cont =True
154+
#loop until the array is sorted
155+
while cont == True:
156+
out =[]
157+
cont = False
158+
#loop till the starting array has no items in it
159+
while len(array) > 0:
160+
#move a random item to the end array
161+
item = randint(0,len(array)-1)
162+
out.append(array[item])
163+
array.remove(array[item])
164+
#test to see if the array is sorted
165+
for i in range(len(out)-1):
166+
if out[i] > out[i+1]:
167+
cont = True
168+
break
169+
array = []+out
170+
171+
print(out)
172+
173+
152174
#sudo bogo sort
153175
def sudo_bogo():
154176
pass
@@ -178,5 +200,5 @@ def pancake():
178200
srt()
179201
print(array, "unsorted")
180202
print()
181-
bogo()
203+
merge_sort()
182204
print(sorted(og), "sorted")

0 commit comments

Comments
 (0)