Adetu
Adetu
CC#
Created by Adetu on 8/6/2023 in #help
❔ 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;

}
4 replies
CC#
Created by Adetu on 10/22/2022 in #help
Functions
I'm wandering if it's possible to get a function to return more than one value of different data types.
18 replies