Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
def bubble_sort(seq):
|
||||
"""Inefficiently sort the mutable sequence (list) in place.
|
||||
seq MUST BE A MUTABLE SEQUENCE.
|
||||
|
||||
As with list.sort() and random.shuffle this does NOT return
|
||||
"""
|
||||
changed = True
|
||||
while changed:
|
||||
changed = False
|
||||
for i in range(len(seq) - 1):
|
||||
if seq[i] > seq[i+1]:
|
||||
seq[i], seq[i+1] = seq[i+1], seq[i]
|
||||
changed = True
|
||||
return seq
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""Sample usage and simple test suite"""
|
||||
|
||||
from random import shuffle
|
||||
|
||||
testset = [_ for _ in range(100)]
|
||||
testcase = testset.copy() # make a copy
|
||||
shuffle(testcase)
|
||||
assert testcase != testset # we've shuffled it
|
||||
bubble_sort(testcase)
|
||||
assert testcase == testset # we've unshuffled it back into a copy
|
||||
Loading…
Add table
Add a link
Reference in a new issue