Classical sorting algorithm-pig nest sorting pigeonhole sort
The principle is similar to bucket sorting. It also requires a very large Pigeon nest. [This is called Bucket in bucket sorting. the name doesn't matter.]
Pigeon nest is actually an array. The index position of the array indicates the value, and the value of the index position indicates the number of occurrences. If all the indexes are 1 or 0, the bucket is sorted.
For example
VaR pigeonhole = new int [100];
The value of pigeonhole [0] indicates the number of occurrences of 0...
The value of pigeonhole [1] indicates the number of occurrences of 1...
The value of pigeonhole [2] indicates the number of occurrences of 2...
ReferenceHttp://hi.baidu.com/wangxvfeng101/blog/item/a2c22560e57260c58cb10d8c.html
The code is for reference only.
/// Nest sorting /// </Summary> /// <Param name = "unsorted"> array to be sorted </param> /// <Param name = "maxnumber"> maximum number of columns in the array to be sorted, </param> /// <returns> </returns> static int [] pogeon_sort (INT [] unsorted, int maxnumber = 10) {int [] pogeonhole = new int [maxnumber + 1]; foreach (VAR item in unsorted) {pogeonhole [item] ++;} return pogeonhole; /** pogeonhole [10] = 4; the meaning is * Four 10 appear in the array to be sorted, the same as the other */} static void main (string [] ARGs) {int [] x = {99, 65, 24, 47, 47, 50, 99, 88, 66, 33, 66, 67, 31, 18, 24 }; vaR sorted = pogeon_sort (x, 99); For (INT I = 0; I <sorted. length; I ++) {for (Int J = 0; j <sorted [I]; j ++) {console. writeline (I) ;}} console. readline ();}
Back to main directory [classic Sorting Algorithm] [Collection]