Java cardinality sorting algorithm based on sorting algorithm

Source: Internet
Author: User

Package Net.qh.test.sort;import java.util.arraylist;import java.util.list;/** * Created by Administrator on 2016/03/07.         */public class Radix {public static int[] ASC (int[] array) {int index = 1;/** maximum number of digits (for example, 100 is 3 digits, 2000 is 4 digits) */ /** gets the maximum number of digits */for (int i = 0; i < Array.Length; i++) {int length = integer.tostring (arra            Y[i]). Length ();            if (Index < length) {index = length;    }} return sort (array, 0, index); }/** * @param array array * @param the exponent starting bit (the actual meaning in the code is: 10 exponent. The starting digit is 10 of 0, so the number of digits is * @param index maximum number digits (e.g. 100 is 3 digits, 2000 is 4 digits) */private static int[] sort (int[] array, int        exponent, int index) {int length = Array.Length; /** Here I choose an array of list instead of Int[n][n] */list<list<integer>> List = new Arraylist<list<integer>> ()        ; for (int i = 0; i < i++) {List.add (New arraylist<integer> ());       /** statistics are sorted by individual digit number */for (int i = 0; i < length; i++) {int num = 0;            String str = integer.tostring (array[i]); if (Str.length ()-exponent-1 >= 0) {num = Integer.parseint (str.substring (Str.length ()-exponent-1            , Str.length ()-exponent));        } list.get (num). Add (Array[i]); }/** string The data in the bucket */for (int k = 0, i = 0; i < list.size (); i++) {for (int j = 0; J < list . get (i). Size ();            J + +) {array[k++] = List.get (i). get (j);        }}/** If there is a higher number, sort by the next digit */if (index = = ++exponent) {return array;        }else{return sort (array, exponent, index); }    }}

  

Java cardinality sorting algorithm based on sorting algorithm

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.