`

java插入排序

阅读更多
目前在研究算法导论,之前去南大富士通面试,问了一堆算法,哎,可惜都忘记干净了,现在拿了一本算法导论第三版 英文版本,配合http://www.verycd.com/entries/531428/电驴的
麻省理工学院开放课的算法导论,自己慢慢将涉及到的各个算法用java实现下,虽然网上一搜一大堆,但是如果自己不敲,不去琢磨,就不是自己的东西,面试的时候难免会不知所以然
public class insertLoop {

public static void main(String[] args) {
   int []a={5,2,4,6,1,3};
   for(int i=1;i<a.length;i++){
   int j=i-1;
   int t=a[i];
   while(j>=0 && a[j]>t){
  int temp=a[j];
  a[j]=t;
  a[j+1]=temp;
  j--;
   }
   }
   for(int i=0;i<a.length;i++){
   System.out.println(a[i]);
  
   }
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics