public static void Main()
int[] array = new int[]{3, 4, -1, 5, 215, -134, 5, 4, 5, 5, 5};
Helpers.PrintArray(array);
public static class Helpers
public static void PrintArray(int[] array)
for (int index = 0; index < array.Length; index++)
Console.Write(array[index] + " ");
private static void Sort(int[] array, int leftIndex, int rightIndex)
if (leftIndex < rightIndex)
int pivotIndex = (leftIndex + rightIndex) / 2;
int pivotNumber = array[pivotIndex];
int counterBiggerIndex = leftIndex;
int counterLowerIndex = rightIndex;
Partition(array, leftIndex, rightIndex, pivotNumber, counterBiggerIndex, counterLowerIndex);
Sort(array, leftIndex, pivotIndex);
Sort(array, pivotIndex + 1, rightIndex);
private static void Partition(int[] array, int leftIndex, int rightIndex, int pivotNumber, int counterBiggerIndex, int counterLowerIndex)
while (counterLowerIndex > counterBiggerIndex)
while (counterBiggerIndex <= rightIndex)
if (array[counterBiggerIndex] > pivotNumber)
while (counterLowerIndex >= leftIndex)
if (array[counterLowerIndex] <= pivotNumber)
if (counterLowerIndex > counterBiggerIndex)
SwapElements(counterBiggerIndex, counterLowerIndex, array);
private static void SwapElements(int index1, int index2, int[] array)
int tempNumber = array[index1];
array[index1] = array[index2];
array[index2] = tempNumber;
public static void Sort(int[] array)
Sort(array, 0, array.Length - 1);