Code: Alles auswählen
static List<int> quickSort(List<int> unsorted, int pivot, ref long count)
{
if (unsorted.Count == 1 || unsorted.Count == 0)
{
return unsorted;
}
else
{
int i = 1;
count = count + unsorted.Count - 1;
if (pivot != 0)
{
swap(ref unsorted, 0, pivot);
}
int pivotElement = unsorted[0];
for (int j = 1; j < unsorted.Count; j++)
{
if (pivotElement > unsorted[j])
{
swap(ref unsorted, i, j);
i++;
}
}
swap(ref unsorted, 0, i - 1);
List<int> left = quickSort(unsorted.GetRange(0, i - 1), pivot, ref count);
left.Add(unsorted[i - 1]);
List<int> right = quickSort(unsorted.GetRange(i, unsorted.Count - i), pivot, ref count);
return left.Concat<int>(right).ToList<int>();
}
}