Sort algorithm Java implementation (cardinality sort)

Source: Internet
Author: User

1  Packagesorting;2 3 /**4 * Base Sort5 * Average O (d (n+r)), preferably O (d (n+r)), Worst O (d (n+r)), Space complexity O (n+r), stable, more complex6 * d is the number of digits, R is the number of the list after distribution7  * @authorZeng8  *9  */Ten  Public classJishupaixu { One  A      Public Static intGetnuminpos (intNumintPOS) { -         intTMP = 1; -          for(inti = 0; i < pos-1; i++) { theTMP *= 10; -         } -         return(num/tmp)% 10; -     } +  -      Public Static intGetmaxweishu (int[] b) { +         intmax = B[0]; A          for(inti = 0; i < b.length; i++) { at             if(B[i] >max) -Max =B[i]; -         } -         intTMP = 1, i = 1; -          while(true) { -TMP *= 10; in             if(Max/tmp! = 0) { -i++; to}Else +                  Break; -         } the         returni; *     } $ Panax Notoginseng      Public Static int[] Jishupaixu (int[] A,intd) { -  the         int[] Array =New int[10] [A.length + 1]; +          for(inti = 0; I < 10; i++) { AArray[i][0] = 0;//Array[i][0] Record number of data in row I the         } +          for(intpos = 0; Pos < D; pos++) { -System.out.println ("Start Fenpei"); $              for(inti = 0; i < a.length; i++) {//Allocation Process $                 intnum = Getnuminpos (a[i], POS + 1); -                 intindex = ++array[num][0]; -System.out.println ("a[" + i + "]-->" + "array[" + num + "] [" the+ index + "]"); -Array[num][index] =A[i];Wuyi             } theSystem.out.println ("Start Shouji"); -              for(inti = 0, j = 0; I < 10; i++) {//Collection Process Wu                  for(intK = 1; K <= Array[i][0]; k++) { -System.out.println ("a[" + j + "]=" + "array[" + i + "] [" About+ K + "]"); $A[j++] =Array[i][k]; -                 } -Array[i][0] = 0;//Reset, the next POS is also required to use -             } A         } +  the         returnA; -     } $  the      Public Static voidMain (string[] args) { the         int[] B = {49, 38, 65, 197, 76, 213, 27, 50 }; the Jishupaixu (b, Getmaxweishu (b)); the          for(inti:b) -System.out.print (i + "")); in  the     } the}

Sort algorithm Java implementation (cardinality sort)

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.