Introduction to Algorithm - Summary of Chapter 2(1) - Insertion sort

来源:互联网 发布:单片机 型号 - 百度 编辑:程序博客网 时间:2024/04/28 18:40

Insertion sort

Insertion sort : It expands the ordered area by place the element into the correct situation when the element is considered.

Insertion-Sort (A)    for j=2 to A.length        key = A[j]        //Insert A[j] into the sorted sequence A[1..j-1]        i = j-1        while i>0 && A[i]>key            A[i+1] = A[i]            i = i-1        A[i+1] = key

The show of insertion sort execution

The insertion sort is stable and in place .

Some of above content refere to “Introduction to Algorithm”.

0 0
原创粉丝点击