算法学习----->Insertsort(插入排序)
来源:互联网 发布:php空间免费 编辑:程序博客网 时间:2024/06/07 19:37
开启算法学习模式,我想看看在这条路上我能坚持多久,每天学习一点点算法,看看做到什么程度才能与现在有所不同。
每天的学习任务我也不想搞得太多,能学习多少就写多少算法博客,今天就学习了Insertsort----->插入排序
首先简单的理解一下插入排序的基本思想:
一个混乱的排列,首先让它的第二项与第一项排序得到一个有序的排列;
然后从混乱的队列中抽取第三项,在于已经排序好的排列中的每一项比较然后进行插入操作;
后面的项都循环的执行这些操作就能实现Insertsort(插入排序)了。
插入排序运用到了数学上的数学归纳法的思想
代码实现:
public class InsertSort {public int[] sort(int[] array) {for (int i = 1; i < array.length; i++) {for (int j = i; j > 0; j--) {int data;if (array[j - 1] > array[j]) {data = array[j];array[j] = array[j - 1];array[j - 1] = data;}}}return array;}public static void main(String[] args) {int[] array = { 5, 2, 12, 6, 13, 56, 1 };InsertSort sort = new InsertSort();int[] result = sort.sort(array);for (int i = 0; i < result.length; i++) {System.out.print(result[i] + "----->");}}}
0 0
- 算法学习----->Insertsort(插入排序)
- InsertSort 插入排序算法
- 排序算法-插入排序 insertSort
- 排序算法-InsertSort-插入排序
- 插入排序算法(InsertSort)
- 经典算法-插入排序Insertsort
- 经典排序算法(2) -插入排序 InsertSort
- 算法导论2.1-insertsort算法(插入排序)
- 算法与数据结构--插入排序(InsertSort)
- 插入排序InsertSort
- insertSort - 插入排序
- 插入排序 InsertSort
- 插入排序 InsertSort
- 插入排序(InsertSort)
- 插入排序InsertSort
- 插入排序-InsertSort
- java insertsort 插入排序
- 插入排序-insertsort
- C语言 Static关键字
- 【树DP】UVA12929Aerial Tramway
- Callable和Future实现调用任务并返回结果数据
- linux grep命令
- 织梦js广告不显示原因,dedecms后台不显示广告预览(最新2016年2月29日)
- 算法学习----->Insertsort(插入排序)
- ios学习笔记(二)--代理设计模式
- [LeetCode]16 最接近的三者之和
- Redis作为多个Windows服务运行配置方法
- Java5中线程池的概念与Executors类的应用
- servlet返回json数据
- First
- 裁切图像设置圆角图像,不使用控件的layer.cornerRadius属性
- 【leetcode】1.Two Sum