Em vừa viết hàm quick sort trong C,khi em chạy thử thì nó hoạt động tốt trong hầu hết TH nhưng với test :{10,9,5,6,7} thì lại sai.Bác naò giải thích cho e với
void swap(double *A,int i,int j){
double tmp;
tmp=A[i];
A[i]=A[j];
A[j]=tmp;
}
void sort(double *A,int l,int r){
int i,j,k;
i=l;j=r;
int x;
x=(l+r)/2;
while(i<=j){
while(A[i]<A[x])i=i+1;
while(A[j]>A[x])j=j-1;
if(i<=j){
swap(A,i,j);
i=i+1;
j=j-1;
}
}
if(l<j)sort(A,l,j);
if(r>i)sort(A,i,r);
}