嫑废话,上代码
- matlab实现
function a=quickSort(a,left,right)
if(left>right)
return;
end;
temp=a(left);
i=left;j=right;
while(i~=j)
while(i<j&&a(j)>=temp)
j=j-1;
end
a(i)=a(j);
while(i<j&&a(i)<=temp)
i=i+1;
end
a(j)=a(i);
end
a(j)=temp;
a= quickSort(a,left,i-1);
a= quickSort(a,i+1,right);
plot(a,'b.');
pause(0.01);
end
```c
2、c语言实现
#include<stdio.h>
void quickSort(int *a,int left,int right){
if(left>right)return;
int temp=a[left];
int i,j;
i=left;j=right;
while(i!=j){
while(a[j]>=temp&&i<j){
j--;
}
while(a[i]<=temp&&i<j){
i++;
}
if(i<j){
int t=a[i];
a[i]=a[j];
a[j]=t;
}
}
a[left]=a[i];
a[i]=temp;
quickSort(a,left,i-1);
quickSort(a,i+1,right);
}
int main(){
int n=9;
int a[]={132,123,422,266,264,264,227,2247,226};
quickSort(a,0,n-1);
for(int i=0;i<n;i++){
printf("%d ",a[i]);
}
}
```c
在这里插入代码片
- java实现
import java.util.Arrays;
public class quick