## Java：快速排序（双指针版） 原

ricardohn

``````
import java.util.Arrays;

public class qucik_sort {

public static void main(String[] args) {
// TODO Auto-generated method stub
int[] scores={5,4,6,3,7,2,8,1,9,10};
int[] scores1={4,2,3};
//System.out.println(partition(scores,0,scores.length));
System.out.println(Arrays.toString(quick_sort(scores,0,scores.length-1)));
//System.out.println(Arrays.toString(quick_sort(scores1,0,scores1.length-1)));
}
public static int partition(int[] arrays,int p,int q){
int x=arrays[p];
int i=p;
int tmp;
int j=q;
while(i <j){
while(i<j && arrays[j]>=x){
j--;}
if(i<j){
tmp=arrays[j];
arrays[j]=arrays[i];
arrays[i]=tmp;
i++;
}
while(i<j && arrays[i]<=x){
i++;}
if(i<j){
tmp=arrays[j];
arrays[j]=arrays[i];
arrays[i]=tmp;
j--;
}

}

return i;
}

public static int[] quick_sort(int[] arrays,int p,int q){
if(p<q){
int r=partition(arrays,p,q);
//System.out.println(r+Arrays.toString(arrays));
quick_sort(arrays,p,r-1);
quick_sort(arrays,r+1,q);

}
return arrays;
}
}
``````

### ricardohn

Sunrise_1018
2018/11/23
0
0
jna调用dll问题

2017/03/13
149
2

} include <jni.h> / Header for class Sample1 / ifndef IncludedSample1 define IncludedSample1 ifdef cplusplus extern "C" { endif /* Class: Sample1 Method: intMethod Signature: (I......

2012/07/12
0
0

2011/05/12
962
5

nanchen2251
2018/07/18
0
0

Git代码防丢指南

joymufeng
7分钟前
0
0

16. chown命令 chown 用来更改一个文件或者目录的所有者护着所属组 -R 级联更改一个目录下所有的目录和文件 chown user1:users 1.txtchown user1.users 1.tx useradd 添加用户的命令 user...

miko0089
17分钟前
0
0

wiki上的描述 Encapsulate a request as an object, thereby allowing for the parameterization of clients with different requests, and the queuing or logging of requests. It also al......

19分钟前
0
0
Optional类的简单了解

import java.util.Optional;/** * @author hanliwei */public class OptionalTest { /** * Optional 类是一个可以为null的容器对象。如果值存在则isPresent()方法会返...

wind2012
27分钟前
0
0

36分钟前
1
0