The following is an almost direct translation of the Flash version of Quicksort I created earlier: http://www.kirupa.com/developer/actionscript/quickSort.htm
private static List<int> QuickSort(List<int> a, int left, int right)
{
int i = left;
int j = right;
double pivotValue = ((left + right) / 2);
int x = a[Convert.ToInt32(pivotValue)];
int w = 0;
while (i <= j)
{
while (a* < x)
{
i++;
}
while (x < a[j])
{
j--;
}
if (i <= j)
{
w = a*;
a[i++] = a[j];
a[j--] = w;
}
}
if (left < j)
{
QuickSort(a, left, j);
}
if (i < right)
{
QuickSort(a, i, right);
}
return a;
}
// Quicksort in C#
static void Main(string[] args)
{
List<int> tempData = new List<int>();
tempData.Add(4);
tempData.Add(24);
tempData.Add(1);
tempData.Add(3);
tempData.Add(5);
List<int> newList = QuickSort(tempData, 0, tempData.Count - 1);
for (int b = 0; b < newList.Count; b++)
{
Console.WriteLine(newList**);
}
}
:disco: