Skip to content

Commit

Permalink
Merge pull request #40 from anumehaagrawal/master
Browse files Browse the repository at this point in the history
Cocktail sort
  • Loading branch information
srbcheema1 authored Oct 1, 2017
2 parents 0bc1393 + 950524c commit c54a4fc
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions algo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Cocktail sorting




def cocktailsort(a):
n=len(a)
swapped=True
start=0
end=n-1
while(swapped==True):
swapped=False

for i in range(start,end):
if (a[i] > a[i+1]) :
a[i], a[i+1]= a[i+1], a[i]
swapped=True
if (swapped==False) :
break
swapped=False
end=end-1
for i in range(end-1,start-1,-1) :
if (a[i] > a[i+1]) :
a[i], a[i+1]= a[i+1], a[i]
swapped=True
start=start+1

a=[8,2,1,3,4]
cocktailsort(a)
print("Sorted array is:")
for i in range(len(a)):
print ("%d" %a[i]),

0 comments on commit c54a4fc

Please sign in to comment.