8000 add cocktail_sort · Deepanshi-Gupta/python@890eca9 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 890eca9

Browse files
panos21kyrabranhe
authored andcommitted
add cocktail_sort
1 parent e090eda commit 890eca9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

algorithms/sorting/cocktail_sort.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def cocktailSort(array)
2+
n = len(array)
3+
swap = 1
4+
begin = 0
5+
end = n-1
6+
#Sorting start
7+
while (swap == 1):
8+
swap = 0
9+
10+
#sorting from begin
11+
for i in range (begin, end):
12+
if (a[i] > a[i+1]) :
13+
a[i], a[i+1]= a[i+1], a[i]
14+
swap=1
15+
16+
if (swap==0):
17+
break swap = 0
18+
19+
end = end-1
20+
#sorting from end
21+
for i in range(end-1, begin-1,-1):
22+
if (a[i] > a[i+1]):
23+
a[i], a[i+1] = a[i+1], a[i]
24+
swap = 1
25+
26+
begin = begin+1

0 commit comments

Comments
 (0)
0