PHP implementation of base sorting

Source: Internet
Author: User
: 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.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.