I am given a programme in C which implements Quicksort on arrays with int values. I need to convert it into a programme which will implement Quicksort on arrays with double* values. I thought that I just need to change "int" declarations into "double*", but for some reason the programme no longer works when I test arrays with other values than integers.
誰か助けてくれませんか?私は C でのプログラミングについてほとんど何も知らず、どうすればよいかわかりません。「int」プログラムは次のとおりです。
void quicksort(int a[], int n)
{
if (n <= 1) return;
int p = a[n/2];
int b[n], c[n];
int i, j = 0, k = 0;
for (i=0; i < n; i++) {
if (i == n/2) continue;
if ( a[i] <= p) b[j++] = a[i];
else c[k++] = a[i];
}
quicksort(b,j);
quicksort(c,k);
for (i=0; i<j; i++) a[i] =b[i];
a[j] = p;
for (i= 0; i<k; i++) a[j+1+i] =c[i];
}
int main(void) {
int i;
/* das Array zum Sortieren */
int test_array[] = { 5, 2, 7, 9, 6, 4, 3, 8, 1 };
int N = sizeof(test_array)/sizeof(int);
quicksort(test_array, N);
for(i = 0; i < N; i++)
printf("%d ", test_array[i]);
printf("\n");
return 0;
}