: This article mainly introduces the PHP implementation of base sorting. if you are interested in the PHP Tutorial, please refer to it. Base sorting is based on the values in the keywords. it is achieved by sorting N elements by several times "allocation" and "collection.
You can use a specific instance to demonstrate how base sorting is performed.
There is an initial sequence: R {50,123,543,187, 49, 30, 0, 2, 11,100 }.
We know that the base of each single digit of any Arabic number is 0 ~ 9.
So we might as well take 0 ~ 9 is considered as 10 buckets.
We first classify the sequence based on the number of single digits and divide it into the specified bucket. For example, if R [0] = 50 and the single digit is 0, the number is saved to the bucket numbered 0.
After classification, we extract all the numbers from each bucket in the order from 0 to 9.
In this case, the obtained sequence is the sequence with ascending single digits.
Sort by single digit: {50, 30, 0,100, 11, 2,123,543,187, 49 }.
Next, we can sort dozens and hundreds of bits in this way, and finally we can get the sorted sequence.
1) {$ m = 0; for ($ j = 0; $ j <10; $ j ++) {for ($ k = 0; $ k
Paixu (array (31,100,100 ))
Result: array ([0] => 3 [1] => 6 [2] => 7 [3] => 8 [4] => 31 [5] => 45 [6] = & gt; 65 [7] = & gt; 100 [8] = & gt; 1000 [9] = & gt; 1234)
The base sorting can also be applied to finding the number of duplicates and finding the number of intervals.
Code is not important (my code still needs to be improved), and the idea is key
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above introduces the PHP implementation of the base sorting, including the content, hope to be helpful to friends who are interested in the PHP Tutorial.