我是靠谱客的博主 甜美墨镜,这篇文章主要介绍插入排序算法,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cn.idestiny.util.GeneratedArray; /** * 插入排序算法实现 */ public class InsertionSort { public static void main(String[] args) { //随机生成指定长度数组 int[] randomarr = GeneratedArray.randomGeneratedArray(50, 60, 10000); //打印为排序的数组 GeneratedArray.printArray(randomarr); long start = System.currentTimeMillis(); for (int i = 1;i<randomarr.length;i++){ int key = randomarr[i]; int j = i-1; while(j>=0&&randomarr[j]<key){ randomarr[j+1] = randomarr[j]; j--; } randomarr[j+1]=key; } System.out.println(System.currentTimeMillis()-start); //打印排序好的数组 GeneratedArray.printArray(randomarr); } }

 

转载于:https://www.cnblogs.com/lfdestiny/p/9536843.html

最后

以上就是甜美墨镜最近收集整理的关于插入排序算法的全部内容,更多相关插入排序算法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(70)

评论列表共有 0 条评论

立即
投稿
返回
顶部