插入排序 (Insertion Sort)
来源:互联网 发布:谁有午夜福利软件 编辑:程序博客网 时间:2024/05/16 14:00
插入排序的基本思想是,经过i-1遍处理后,L[1..i-1]己排好序。第i遍处理仅将L[i]插入L[1..i-1]的适当位置,使得L[1..i]又是排好序的序列。要达到这个目的,我们可以用顺序比较的方法。首先比较L[i]和L[i-1],如果L[i-1]≤ L[i]騆[1..i]已排好序,第i遍处理就结束了;否则交换L[i]与L[i-1]的位置,继续比较L[i-1]和L[i-2],直到找到某一个位置j(1≤j≤i-1),使得L[j] ≤L[j+1]时为止。
平均时间复杂度:O(n2)
Jave Code:
public class InsertionSort {public static float[] InsertionSortAlgorithm(float flt[], int length){float sortedFlt[]=flt;for(int i=0;i<length-1;i++){for(int j=i+1;j>0;j--){if (flt[j]<flt[j-1]) {float temp=flt[j-1];flt[j-1]=flt[j];flt[j]=temp;}else{break;}}}return sortedFlt;}}
- 插入排序(insertion sort)
- insertion sort 插入排序
- 插入排序(Insertion Sort)
- 插入排序 Insertion Sort
- 插入排序Insertion sort
- 插入排序 (Insertion Sort)
- 插入排序Insertion sort
- 插入排序 Insertion Sort
- 插入排序 insertion sort
- 插入排序 insertion sort
- 插入排序Insertion sort
- 插入排序 Insertion sort
- 插入排序 Insertion Sort
- 插入排序-----Insertion Sort
- INSERTION-SORT插入排序
- 插入排序Insertion Sort
- insertion sort(插入排序)
- 插入排序-Insertion sort
- 377. Set a thief to catch a thief. 以贼捉贼
- android杂谈
- sql语句优化
- 冒泡排序 (Bubble Sort)
- 商务智能-基本方法-树结构下钻
- 插入排序 (Insertion Sort)
- 选择排序 (Selection Sort)
- 快速排序 (Quick Sort)
- 推荐系统-从入门到精通
- 关于如何提取代码成为函数,自己浅薄的一些看法
- Perl求中值
- js查找元素的方法
- 解决ORACLE的EM登录
- 异常处理的权衡