Data Structures and Algorithm Analysis in C —— Sorting

Start trying to write a blog in English, so start now!
Insertion sort
One of the simplest sorting algorithms is insertion sort. Insertion sorting consists of N-1 pass sorting. For P=1 to P=N-1, insertion sort ensures that the elements from position 0 to position P are sorted. Insertion sort takes advantage of the fact that the elements from position 0 to position P-1 are already sorted.
Insertion sort routine:
1 | void InsertionSort(ElementType A[], int N){ |
Lines 2 to 5 implement data movement without obvious use of exchange. Store the element at position P in Tmp, and (before position P) all lager elements move one position to the right. Place the Tmp in the correct position after you let it go. This method is the same as the technique used when implementing a binary head.
评论
评论插件加载失败
正在加载评论插件