Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 7, 2025. It is now read-only.

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)

AltStyle によって変換されたページ (->オリジナル) /