Code
/// <summary>
/// Implement the Quick Sort algorithm.
/// </summary>
/// <param name="ArrayEx">The array will be sorted</param>
/// <param name="start">the index of the first element of the array</param>
/// <param name="end">the last index of the array</param>
public static void QuickSort(int[] ArrayEx, int start, int end)
{
if (end - start > 0) // the length of the array must be greater than 1.
{
int pivot = ArrayEx[end];//set the last menber to the pivot
//You can choose one in the array anywhere
int j = start; //set a pointer
for (int i = start; i <= end; i++)
{
if (ArrayEx[i] < pivot)
{
swap(ref ArrayEx[i], ref ArrayEx[j]);
j++;//swap the value and than the j point the next one.
}
}
swap(ref ArrayEx[j], ref ArrayEx[end]);
// *************************************************************************************************
// depart the array into two piececs than call the method again till the length of the piecec is one.
// *************************************************************************************************
QuickSort(ArrayEx, start, j - 1);
QuickSort(ArrayEx, j + 1, end);
}
}