all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
def cocktailSort(A):
|
||||
up = range(len(A)-1)
|
||||
while True:
|
||||
for indices in (up, reversed(up)):
|
||||
swapped = False
|
||||
for i in indices:
|
||||
if A[i] > A[i+1]:
|
||||
A[i], A[i+1] = A[i+1], A[i]
|
||||
swapped = True
|
||||
if not swapped:
|
||||
return
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
test1 = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0]
|
||||
cocktailSort(test1)
|
||||
print test1
|
||||
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
test2=list('big fjords vex quick waltz nymph')
|
||||
cocktailSort(test2)
|
||||
print ''.join(test2)
|
||||
#>>> abcdefghiijklmnopqrstuvwxyz
|
||||
Loading…
Add table
Add a link
Reference in a new issue