Skip to content

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy