【java实现】算法导论之插入排序递归



public class INSERT_SORT {
public static void Insert(int arrs[],int p,int r){
for(int i=p;i int key=arrs[i];
int j=i-1;
while(j>=0&&arrs[j]>key){
arrs[j+1]=arrs[j];
j--;
}
arrs[j+1]=key;
}
}
public static void Insert_sort(int[] arrs,int p,int r){
if(p r=r-1;
Insert_sort(arrs,p,r);
Insert(arrs,p,r);
}
}
public static void main(String[] args){
int[] A={3,41,52,26,38,57,9,49};
System.out.print("待排序数组为:");
for(int i=0;i System.out.print(A[i]+"\t");
}
Insert_sort(A,0,A.length-1);
System.out.println();
System.out.print("排好序的数组为:");
for(int i=0;i System.out.print(A[i]+"\t");
}
}
}

你可能感兴趣的:(【java实现】算法导论之插入排序递归)