❔ Problem with Quick Sort
It seems that it partially sorts it and doesn't finish. I really can't see what is wrong
void QuickSort(int[] A, int left, int right)
{
if (left < right)
{
int pivotIndex = Partition(A, left, right);
QuickSort(A, left, pivotIndex - 1);
QuickSort(A, pivotIndex + 1, right);
}
}
int Partition(int[] A, int left, int right)
{
int p = A[left];
int i = left + 1;
for (int j = left + 1; j < right; j++)
{
if (A[j] <= p)
{
int temp1 = A[j];
A[j] = A[i];
A[i] = temp1;
i += 1;
}
int temp2 = A[i - 1];
A[i - 1] = A[left];
A[left] = temp2;
}
return i - 1;
} void QuickSort(int[] A, int left, int right)
{
if (left < right)
{
int pivotIndex = Partition(A, left, right);
QuickSort(A, left, pivotIndex - 1);
QuickSort(A, pivotIndex + 1, right);
}
}
int Partition(int[] A, int left, int right)
{
int p = A[left];
int i = left + 1;
for (int j = left + 1; j < right; j++)
{
if (A[j] <= p)
{
int temp1 = A[j];
A[j] = A[i];
A[i] = temp1;
i += 1;
}
int temp2 = A[i - 1];
A[i - 1] = A[left];
A[left] = temp2;
}
return i - 1;
}