quicksort.java
来自「QuickSort,SelectSort用Eclipse实现」· Java 代码 · 共 45 行
JAVA
45 行
public class QuickSort {
/**
* @param args
*/
public static void main(String[] args) {
for(int i=0;i<a.length;i++){
System.out.printf("%6d", a[i]);
}
sort(a, 0, a.length);
for(int i=0;i<a.length;i++){
System.out.printf("%6d", a[i]);
}
// TODO Auto-generated method stub
}
private static void sort(int[] a,int low,int high)
{
if(low<high){
int pivotloc=Partition(a,low,high);
sort(a,low,pivotloc-1);
sort(a,pivotloc+1,high);
}
}
private static int Partition(int[] a,int low,int high){
int pivotkey=a[low];
while(low<high){
while(low<high&&a[high]>=pivotkey)--high;
swap(a,low,high);
while(low<high&&a[low]<=pivotkey)++low;
swap(a,low,high);
}
return low;
}
private static void swap(int[] a,int low,int high){
int temp=a[low];
a[low]=a[high];
a[high]=temp;
}
static int []a={12,39,30,83,34,22,68};
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?