Skip to content

Commit 27777e9

Browse files
authored
Create OddEvenSort.py
1 parent 78d8a9b commit 27777e9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

allalgorithms/sorting/OddEvenSort.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: UTF-8 -*-
2+
#
3+
# OddEven Sort Algorithm
4+
# The All ▲lgorithms library for python
5+
#
6+
# Contributed by: Cayo Viegas
7+
# Github: @CayoViegas
8+
#
9+
10+
def oddEvenSort(arr, n):
11+
isSorted = 0
12+
while isSorted == 0:
13+
isSorted = 1
14+
temp = 0
15+
for i in range(1, n-1, 2):
16+
if arr[i] > arr[i+1]:
17+
arr[i], arr[i+1] = arr[i+1], arr[i]
18+
isSorted = 0
19+
20+
for i in range(0, n-1, 2):
21+
if arr[i] > arr[i+1]:
22+
arr[i], arr[i+1] = arr[i+1], arr[i]
23+
isSorted = 0
24+
25+
return arr
26+

0 commit comments

Comments
 (0)