插入排序(InsertionSort)
2014-06-13 20:54
344 查看
位置p上的元素存储于tmp(第一趟p通常取1),而(位置p之前)所有更大的元素都向右移动一个位置。
然后tmp被放在正确的位置上。
代码:
然后tmp被放在正确的位置上。
代码:
public class InsertionSort { private int q; int[] insertionSort(int[] a) { for (int p = 1; p < a.length; p++) { int temp = a[p]; for (q = p; q > 0 && (temp - a[q - 1]) < 0; q--) a[q] = a[q - 1]; a[q] = temp; } return a; } }
相关文章推荐
- 【LeetCode-面试算法经典-Java实现】【147-Insertion Sort List(链表插入排序)】
- Insertion Sort List 使用插入排序将链表排序
- 插入排序(Insertion Sort)
- 静态链表插入排序(List Insertion Sort)算法
- [C++]LeetCode: 126 Insertion Sort List (插入排序链表)
- [LeetCode147]Insertion Sort List(链表插入排序)
- AOJ-ALDS1_1_A Insertion Sort【插入排序】
- 【算法】插入排序 insertion_sort
- 排序算法 之 插入排序InsertionSort
- 经典排序算法 – 插入排序Insertion sort
- 插入排序(Insertion Sort)
- [硕.Love Python] InsertionSort(插入排序)
- PHP Array -- PHP排序 -- 插入排序(Insertion Sort)
- InsertionSort -- 插入排序(C++)
- Insertion Sort(插入排序)
- 插入排序(Insertion sort)
- 2.1 插入排序(insertion_sort)
- leetcode——Insertion Sort List 对链表进行插入排序(AC)
- 插入排序(Insertion Sort List)
- 算法排序--插入排序(insertion sort)