In the previous discussion, the insertion sort, merge sort, heap sort and quick sort are all based on the comparison sorting algorithm, and for all the comparison sorting algorithms, the complexity of the algorithm is also O (NLGN). For the proof process, refer to the eighth chapter of the Introduction to Algorithms section I.
Today introduces a non-comparative sort, named Count sort.
The basic idea is that for each element, the element is determined to be less than the number of the element, and it can be placed in the correct position. The algorithm can achieve linear time complexity, i.e. O (n).
Program, array A is an input array (unordered array), B is an output array, and C is an intermediate array. 20 means that each element in the array is assumed to be a nonnegative integer less than 20.
Counting sorting and C language implementation