原理图:

java shell排序

package suanfa;
public class shellInsert { public void shellInsert1(double [] sorted,int inc){ int sorted_length=sorted.length; for(int i=inc+1;i<sorted_length;i++){ if(sorted[i]<sorted[i-inc]){ sorted[0]=sorted[i]; int insertpos=i; for(int k=i-inc;k>=0;k--){ if(sorted[k]>sorted[0]){ sorted[k+inc]=sorted[k]; if(k-inc<0){ insertpos=k; } } else{ insertpos=k+inc; break; } } sorted[insertpos]=sorted[0]; } } } public static void main(String[] args) { // TODO Auto-generated method stub double [] sorted=new double[]{0.0,9.8,2.3,4.5,6.7,1.2,7.5,2.3,4.5,6.7}; int[] incs={7,5,3,1}; shellInsert shell=new shellInsert(); for (int i=0;i<incs.length;i++){ shell.shellInsert1(sorted, incs[i]); } } }

 

相关文章:

  • 2021-06-01
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-24
  • 2021-06-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-10
  • 2021-07-07
  • 2022-01-06
  • 2022-12-23
  • 2021-04-30
相关资源
相似解决方案