我正在尝试制作对c字符串而不是int进行排序的quicksort。当我调用quickSort时,我数组中的所有字符串都被清空并且未排序,我不知道为什么
''''''''''''''''''''''''''''''''''' >
void swap(char** A,int i,int j){
//printf("swap\n");
char* temp=malloc(strlen(A[i])*sizeof(char));
temp = A[i];
free(A[i]);
A[i]=malloc((1+strlen(A[j])) * sizeof(char));
A[i] = A[j];
free(A[j]);
A[j] = malloc((1+strlen(temp)) * sizeof(char));
A[j]=temp;
}
int Partition(char** A,int p,int r){
//printf("partion\n");
int i,j;
char* x;
//printf("x\n");
x = A[r];
i = p-1;
for(j=p; j<r; j++){
if( strcmp(A[j],x) < 0){
i++;
swap(A,i,j);
}
}
swap(A,i+1,r);
return(i+1);
}
void QuickSort(char** A,int r){
int q;
if( p<r ){
q = Partition(A,p,r);
QuickSort(A,q-1);
QuickSort(A,q+1,r);
}
}
'''''''''''''''''''''''''''