Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 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
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
def cocktail(a):
|
||||
for i in range(len(a)//2):
|
||||
swap = False
|
||||
for j in range(1+i, len(a)-i):
|
||||
if a[j] < a[j-1]:
|
||||
a[j], a[j-1] = a[j-1], a[j]
|
||||
swap = True
|
||||
if not swap:
|
||||
break
|
||||
swap = False
|
||||
for j in range(len(a)-i-1, i, -1):
|
||||
if a[j] < a[j-1]:
|
||||
a[j], a[j-1] = a[j-1], a[j]
|
||||
swap = True
|
||||
if not swap:
|
||||
break
|
||||
Loading…
Add table
Add a link
Reference in a new issue