Sort (1): Insert sort, sort insert
Preface
The data structure and algorithm will soon be crushed into slag, and it is decided to start population.
References: Introduction to Algorithms (MIT open course-Introduction to Algorithms), Data Structures and Algorithms in Python, Data Structures and Algorithms
Insertion-sort)
The basic idea of insert sorting: Insert a sorted record to the appropriate position in the subtable that has been sorted in the previous order according to its keyword size
Until all records are inserted.
For example, 8 letters are sorted by insert. Each row corresponds to an outer iteration loop, and each copy in each row corresponds to an inner iteration loop,
The elements in the inserted array are highlighted.
Code Implementation (python ):
1 def insertion_sort (A): 2 for k in range (1, len ()): 3 cur = A [k] # current element to be inserted4 j = k # find correct index j for currect5 while j> 0 and A [J-1]> cur: 6 A [j] = A [J-1] 7 j-= 18 A [j] = cur # cur is now in the rimo-place
Unfinished...
Link recommendations:
MIT open course Introduction to algorithms Study Notes: http://www.cnblogs.com/diliwang/p/3352946.html
Introduction to algorithms Reading Notes: http://www.cnblogs.com/Anker/category/436374.html
.........
Note: Please indicate the source for reprinting.