bottomUpSort 我想呢,好久终于在相通呢,现在贴在这里,好记性不如烂笔头。 归并 排序
package chapter1;public class MERGE { //0<=p<=q<=A.length public void merge(int[] A,int p,int q,int r){ int s=p,t=q+1,k=p; int[] B = A.clone(); while(s<=q && t<=r){ if(A[s]<=A[t]){ B[k]=A[s]; s++; } else{ B[k]=A[t]; t++; } k++; } if(s==(q+1)){ while(k<=r){ B[k]=A[t]; k++;t++; } } else{ while(k<=r){ B[k]=A[s]; k++; s++; } } for(int i=p;i<=r;i++) { A[i]=B[i]; } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] array = {2,3,66,7,11,13,45,57}; MERGE merge=new MERGE(); merge.merge(array, 0, 3, 4); for(int i:array) System.out.print(i+" "); }}
置底向下 排序
package chapter1;public class BOTTOMUPSORT { public void bottomUpSort(int[] A){ int t=1; while(t