Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,40 @@
|
|||
"""
|
||||
|
||||
Python example of
|
||||
|
||||
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort_with_shifting_bounds
|
||||
|
||||
based on
|
||||
|
||||
http://rosettacode.org/wiki/Sorting_algorithms/Cocktail_sort#Python
|
||||
|
||||
"""
|
||||
|
||||
def cocktailshiftingbounds(A):
|
||||
beginIdx = 0
|
||||
endIdx = len(A) - 1
|
||||
|
||||
while beginIdx <= endIdx:
|
||||
newBeginIdx = endIdx
|
||||
newEndIdx = beginIdx
|
||||
for ii in range(beginIdx,endIdx):
|
||||
if A[ii] > A[ii + 1]:
|
||||
A[ii+1], A[ii] = A[ii], A[ii+1]
|
||||
newEndIdx = ii
|
||||
|
||||
endIdx = newEndIdx
|
||||
|
||||
for ii in range(endIdx,beginIdx-1,-1):
|
||||
if A[ii] > A[ii + 1]:
|
||||
A[ii+1], A[ii] = A[ii], A[ii+1]
|
||||
newBeginIdx = ii
|
||||
|
||||
beginIdx = newBeginIdx + 1
|
||||
|
||||
test1 = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0]
|
||||
cocktailshiftingbounds(test1)
|
||||
print(test1)
|
||||
|
||||
test2=list('big fjords vex quick waltz nymph')
|
||||
cocktailshiftingbounds(test2)
|
||||
print(''.join(test2))
|
||||
Loading…
Add table
Add a link
Reference in a new issue