This C# Program Implements Quick Sort.Quicksort is a divide and conquer algorithm. Here Quicksort first divides a large array into two smaller sub-array: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays

Here is source code of the C# Program to Implement Quick Sort. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

`/*`

`* C# Program to Implement Quick Sort`

`*/`

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

`namespace sortQuick`

`{`

`class quickSort`

`{`

private int[] array = new int[20];

private int len;

public void QuickSort()

`{`

sort(0, len - 1);

`}`

public void sort(int left, int right)

`{`

int pivot, leftend, rightend;

leftend = left;

rightend = right;

pivot = array[left];

while (left < right)

`{`

while ((array[right] >= pivot) && (left < right))

`{`

`right--;`

`}`

if (left != right)

`{`

array[left] = array[right];

`left++;`

`}`

while ((array[left] <= pivot) && (left < right))

`{`

`left++;`

`}`

if (left != right)

`{`

array[right] = array[left];

`right--;`

`}`

`}`

array[left] = pivot;

pivot = left;

left = leftend;

right = rightend;

if (left < pivot)

`{`

sort(left, pivot - 1);

`}`

if (right > pivot)

`{`

sort(pivot + 1, right);

`}`

`}`

public static void Main()

`{`

quickSort q_Sort = new quickSort();

int[] array = { 4, 3, 1, 4, 6, 7, 5, 4, 32, 5, 26, 187, 8 };

q_Sort.array = array;

q_Sort.len = q_Sort.array.Length;

q_Sort.QuickSort();

for (int j = 0; j < q_Sort.len; j++)

`{`

Console.WriteLine(q_Sort.array[j]);

`}`

Console.ReadKey();

`}`

`}`

`}`

Here is the output of the C# Program:

1 3 4 4 4 5 5 6 7 8 26 32 187

**Sanfoundry Global Education & Learning Series – 1000 C# Programs.**

If you wish to look at all C# Programming examples, go to 1000 C# Programs.