📄 fastsort.java
字号:
//快速排序算法的实现
//09_20
//lw
package clapackage;
public class FastSort{
public static int Sort(int[] a,int low,int high){//排序基本算法
int tag=a[low];//设置关键码
while(low<high){//
while(low<high && tag<a[high]){//
high--;//向后搜索指针减1
}
a[low]=a[high];a[high]=tag;//交换数字
while(low<high && tag>a[low]){//
low++;//向前搜索指针加1
}
a[high]=a[low];a[low]=tag;//交换数字
}
return low;//返回标志位
}
public static void Recursive(int[] a,int low,int high){//递归调用
int flag;
if(low<high){
flag=Sort(a,low,high);//获取标志位
Recursive(a,low,flag-1);//递归调用Recursive函数
Recursive(a,flag+1,high);
}
}
public static void Print(int[] a){//打印排序后数组
for(int i=0;i<10;i++){
System.out.println(a[i]);
}
}
public static void main(String[] args){
int a[]={10,9,8,7,6,5,4,3,2,1};//声明并初始化数组
int len=9;
Recursive(a,0,len);
Print(a);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -