- public class 希尔排序 {
-
- public static void main(String[] args) {
- int[] a={49,38,65,97,76,13,27,49,78,34,12,64,1};
- System.out.println("排序之前:");
- for (int i = 0; i < a.length; i++) {
- System.out.print(a[i]+" ");
- }
- //希尔排序
- int d = a.length;
- while(true){
- d = d / 2;
- for(int x=0;x<d;x++){
- for(int i=x+d;i<a.length;i=i+d){
- int temp = a[i];
- int j;
- for(j=i-d;j>=0&&a[j]>temp;j=j-d){
- a[j+d] = a[j];
- }
- a[j+d] = temp;
- }
- }
- if(d == 1){
- break;
- }
- }
- System.out.println();
- System.out.println("排序之后:");
- for (int i = 0; i < a.length; i++) {
- System.out.print(a[i]+" ");
- }
- }
- }
复制代码
这希尔排序,毕老师说这种速度很快,没有必要掌握,了解就行。 |