I copy an
int
char
extern void quickSortChar(char a[], int left, int right)
{
int j;
if (left < right)
{
j = partition(a, left, right);
quickSort(a, left, j - 1);
quickSort(a, j + 1, right);
}
}
static int partition(char a[], int left, int right)
{
int pivot, i, j, t;
pivot = a[left];
i = left; j = right + 1;
while (1)
{
do i++; while (a[i] <= pivot && i <= right);
do j--; while (a[j] > pivot);
if (i >= j) break;
t = a[i]; a[i] = a[j]; a[j] = t;
}
t = a[left]; a[left] = a[j]; a[j] = t;
return j;
}
void main()
{
char arr[] = "bacgd";
puts(arr);
quickSortChar(arr, 0, strlen(arr) - 1);
puts(arr);
system("pause");
}
abcdg
abcgd
You're calling quickSort()
recursively (wrong function name) inside quickSortChar()
.
After fixing this bug, it runs and produces good output on my machine:
$ ./program
bacgd
abcdg