The pseudocode of QuickSort is following:
QUICKSORT(A, p, r )
if p < r
then q ←PARTITION(A, p, r )
QUICKSORT(A, p, q − 1)
QUICKSORT(A, q + 1, r )
=================================
PARTITION(A, p, r )
x ← A[r ]
i ← p − 1
for j ← p to r − 1
do if A[ j ] ≤ x
then i ← i + 1
exchange A[i ] ↔ A[ j ]
exchange A[i + 1] ↔ A[r ]
return i + 1
Code
1namespace QuickSort
2{
3 public class Class1
4 {
5
6
7 static void Main()
8 {
9 int[] arraySort = new int[]{12,25,41,5,7,85,45,16,89,54,11,23,46 };
10 QuickSorter quickSort = new QuickSorter();
11 int[] sorted=quickSort.QuickSort(arraySort,0,arraySort.Length-1);
12 for (int i = 0; i < sorted.Length - 1;i++ )
13 {
14 Console.Write(sorted[i]+" ");
15 }
16 Console.Read();
17 }
18 }
19
20 public class QuickSorter
21 {
22 public int[] QuickSort(int[] array, int p, int r)
23 {
24 if (p < r)
25 {
26 int q = Partition(array, p, r);
27 QuickSort(array, p, q - 1);
28 QuickSort(array, q + 1, r);
29 }
30 return array;
31 }
32
33 public int Partition(int[] array, int p, int r)
34 {
35 int x = array[r];
36 int i = p - 1;
37 for (int j = p; j <= r - 1; j++)
38 {
39 if (array[j] <= x)
40 {
41 i += 1;
42 int temp;
43 temp = array[i];
44 array[i] = array[j];
45 array[j] = temp;
46 }
47
48 }
49 int temp2;
50 temp2 = array[i + 1];
51 array[i + 1] = array[r];
52 array[r] = temp2;
53 return i+1;
54 }
55
56 }
57}