sorting algorithm
  • Introduction
  • Wikipedia-sorting-algorithm
  • sorting algorithm
  • 历史 History
  • 分类 Classification
    • 稳定性 Stability
  • 算法比较 Comparison of algorithms
  • 流行排序算法 Popular sorting algorithms
    • 简单排序 Simple sorts
      • 插入排序 Insertion sort
      • 选择排序 Selection sort
    • 高效排序 Efficient sorts
      • 合并排序 Merge sort
      • 堆排序 Heapsort
      • 快速排序 Quicksort
    • 冒泡排序与变种 Bubble sort and variants
      • 冒泡排序 Bubble sort
      • 希尔排序 Shellsort
      • 梳排序 Comb sort
    • 分发排序 Distribution sort
      • 计数排序 Counting sort
      • 桶排序 Bucket sort
      • 基数排序 Radix sort
  • 内存使用模式和索引排序 Memory usage patterns and index sorting
  • 相关算法 Related algorithms
  • 另见 See also
  • 参考文献 References
  • 进一步阅读 Further reading
  • 外部链接 External links
Powered by GitBook
On this page
  • Insertion sort插入排序算法
  • principle原理
  • example示例

Was this helpful?

  1. 流行排序算法 Popular sorting algorithms
  2. 简单排序 Simple sorts

插入排序 Insertion sort

Previous简单排序 Simple sortsNext选择排序 Selection sort

Last updated 5 years ago

Was this helpful?

Insertion sort插入排序算法

@See @See - InsertSort

principle原理

从列表第一位开始向高位进行排序 每次取一位向下沉底排序 双for循环推进排序

example示例

@Override
    public void sort(int[] list) {
        if (list != null && list.length > 1) {
            for (int i = 1; i < list.length; i++) {
                for (int j = i; j > 0; j--) {
                    if (list[j] < list[j - 1]) {
                        swap(list, j, j - 1);
                    } else {
                        break;
                    }
                }
            }
        }
    }
https://en.wikipedia.org/wiki/Insertion_sort
https://github.com/jiek2529/java_algorithm