📄 quicksorter.java
字号:
//
// This class sorts an array using the QuickSort method.
public class QuickSorter
{
private int[] a;
public QuickSorter(int[] anArray)
{
a=anArray;
}
public void sort(int from, int to)
{
if (from>=to)
return;
int p = partition(from,to);
sort(from,p);
sort(p+1,to);
}
private int partition(int from, int to)
{
int temp;
int pivot = a[from];
int i = from-1;
int j = to +1;
while(i<j)
{
i++;
while (a[i]<pivot)
i++;
j--;
while(a[j]>pivot)
j--;
if(i<j)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
return j;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -