InsertSort java 实现
来源:互联网 发布:英语单词读法软件 编辑:程序博客网 时间:2024/05/22 23:27
最简单的排序算法——插入排序。代码中有计算排序耗费时间的计算countTime(),以毫秒计算排序过程花费了多长时间。
// ArgDemo1.javaimport java.util.*;public class ArgDemo1 {public static void printArray(int[] ary) {for (int i=0; i<ary.length; i++){if (i%10 == 0) System.out.println(); System.out.print(ary[i]+"\t");}System.out.println();}public static long countTime(){java.util.Calendar c = java.util.Calendar.getInstance();return (c.getTimeInMillis());}public static void InsertSort(int[] a){int key=0;int i=0;int j=0;//System.out.println("===Starting Insert sort===");for(j=1; j<a.length; j++) {key = a[j];i = j-1;//System.out.println("key= "+key);while(i>=0 && a[i]>key){//System.out.println("key= "+key);a[i+1] = a[i];i--;//printArray(a);}a[i+1] = key;}//System.out.println("===End Insert sort===");}public static void main(String[] arg) {int N = 10;int [] arryTemp = new int[N];long time = 0;System.out.println("------Random Array-------");for (int i=0; i<N; i++){Random rand = new Random();arryTemp[i]=rand.nextInt(N);}printArray(arryTemp);// sort Arraytime = countTime();InsertSort(arryTemp);time = countTime() - time;System.out.println("\n------Sorted Array-------");printArray(arryTemp);System.out.println("\nSort time: "+time+" Millions Second.");}}// Output EX.://------Random Array-------////0 281515264////------Sorted Array-------////0 112245568////Sort time: 0 Millions Second.//~
- InsertSort java 实现
- 插入排序(Insertsort)之Java实现
- 插入排序(Insertsort)之Java实现
- 数据算法之插入排序(insertSort)的Java实现
- java insertsort 插入排序
- InsertSort
- insertsort
- InsertSort
- InsertSort
- insertsort
- insertsort
- insertSort
- insertSort
- InsertSort
- InsertSort
- InsertSort
- insertsort
- java数据结构和算法(InsertSort)
- 谷歌GDG智能技术在物联网及移动互联网中的最新应用讲座
- android ndk增加对stl的支持
- 纯Javascript实现Windows 8 Metro风格实现
- 2013电商新趋势-数据剖析
- eclipse下导入jdk源码
- InsertSort java 实现
- Spring3 Annotation + Hibernate3-jpa2.0 + CGLIB + 多数据源(动态数据源)
- cocos2d-x教程2 精灵
- Android 神模拟器genymotion安装
- [MySQL] 字符集和排序方式
- LU分解版本2_选主元、非原地存储
- linuxmint/ubuntu 修改主机名hostname
- CICS&DB2连接
- 网页截图工具WebThumb