Classic Sort algorithm-pigeon nest sort pigeonhole
The principle is similar to the bucket sort, also need a very big pigeon nest [bucket sort tube This is called bucket, name doesn't matter]
The Pigeon nest is actually an array, the index position of the array represents the value, the value of the index position indicates the number of occurrences, if all are 1 or 0 times that is the bucket sort
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 ...
Reference http://hi.baidu.com/wangxvfeng101/blog/item/a2c22560e57260c58cb10d8c.html
The code is for reference only, welcome Anthony Mistake
Pigeon Nest Sort///</summary>//<param name= "unsorted" > Waiting array </param>//< param name= "MaxNumber" > The maximum number in the array to be queued, if specified </param>//<returns></returns> static int[
] Pogeon_sort (int[] unsorted, int maxnumber = ten) {int[] Pogeonhole = new Int[maxnumber + 1];
foreach (var item in unsorted) {pogeonhole[item]++;
} return pogeonhole; /* * POGEONHOLE[10] = 4;
The implication is that there are 4 10 occurrences in the array to be queued, the same as 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.WR
Iteline (i);
} } console.readline (); }