From 27777e96dcd0e84d17bf4952d0e5be944090896c Mon Sep 17 00:00:00 2001 From: CayoViegas <50140892+CayoViegas@users.noreply.github.com> Date: Fri, 18 Oct 2019 16:53:04 -0300 Subject: [PATCH] Create OddEvenSort.py --- allalgorithms/sorting/OddEvenSort.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 allalgorithms/sorting/OddEvenSort.py diff --git a/allalgorithms/sorting/OddEvenSort.py b/allalgorithms/sorting/OddEvenSort.py new file mode 100644 index 0000000..d64c682 --- /dev/null +++ b/allalgorithms/sorting/OddEvenSort.py @@ -0,0 +1,26 @@ +# -*- coding: UTF-8 -*- +# +# OddEven Sort Algorithm +# The All â–²lgorithms library for python +# +# Contributed by: Cayo Viegas +# Github: @CayoViegas +# + +def oddEvenSort(arr, n): + isSorted = 0 + while isSorted == 0: + isSorted = 1 + temp = 0 + for i in range(1, n-1, 2): + if arr[i] > arr[i+1]: + arr[i], arr[i+1] = arr[i+1], arr[i] + isSorted = 0 + + for i in range(0, n-1, 2): + if arr[i] > arr[i+1]: + arr[i], arr[i+1] = arr[i+1], arr[i] + isSorted = 0 + + return arr +