diff --git a/odd_even_sort/c#/odd_even_sort.cs b/odd_even_sort/c#/odd_even_sort.cs new file mode 100644 index 00000000..15b16944 --- /dev/null +++ b/odd_even_sort/c#/odd_even_sort.cs @@ -0,0 +1,34 @@ +public class OddEvenSort +{ + private static void SortOddEven(int[] input, int n) + { + var sort = false; + + while (!sort) + { + sort = true; + for (var i = 1; i < n - 1; i += 2) + { + if (input[i] <= input[i + 1]) continue; + var temp = input[i]; + input[i] = input[i + 1]; + input[i + 1] = temp; + sort = false; + } + for (var i = 0; i < n - 1; i += 2) + { + if (input[i] <= input[i + 1]) continue; + var temp = input[i]; + input[i] = input[i + 1]; + input[i + 1] = temp; + sort = false; + } + } + } + + public static int[] Main(int[] input) + { + SortOddEven(input, input.Length); + return input; + } +} \ No newline at end of file