Movatterモバイル変換


[0]ホーム

URL:


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.
/pythonPublic archive

Commit890eca9

Browse files
panos21kyrabranhe
authored andcommitted
add cocktail_sort
1 parente090eda commit890eca9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
defcocktailSort(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+
foriinrange (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+
breakswap=0
18+
19+
end=end-1
20+
#sorting from end
21+
foriinrange(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)

[8]ページ先頭

©2009-2025 Movatter.jp