Java Cardinality Ordering

Source: Internet
Author: User

The code is as follows:

Import Java.util.arrays;public class Multikeyradixsort {public static void Radixsort (int [] data, int radix, int d) {System . OUT.PRINTLN ("Start sort:"); int length = data.length;//requires a temporary array int [] tmp = new int [length];//buckets array is bucket sort must buckets array int[]  Buckets = new int[radix];//treats sorted data sequentially from the highest-level sub-keywords//The following loop in which the rate is used to hold the current computed bits (such as 10-bit time rate =10) for (int i = 0, rate = 1;i < D        i++) {//Resets the count array to start counting the second keyword Arrays.fill (buckets, 0);        Copies the elements of the data array into the temporary array for caching system.arraycopy (data, 0, tmp, 0, length);  Computes the sub-key for each data to be sorted for (int j = 0;j < length;j++) {//the keyword int subkey = (tmp[j]/rate) at the specified position of the calculated data        % Radix;        buckets[subkey]++;        } for (int j = 1;j < Radix; J + +) {Buckets[j] = Buckets[j] + buckets[j-1];        Sort specified data by sub-keyword for (int m = length-1;m >=0;m--) {int subkey = (tmp[m]/rate)% Radix;        Data[--buckets[subkey]] = tmp[m]; } SYSTEM.OUT.PRintln ("+rate+" bit on sub-keywords: "+ java.util.Arrays.toString (data)");        Rate *= Radix; }}public static void Main (string[] args) {int[] data = {1100,192,221,12,13}; System.out.println ("before sorting: \ n" + java.util.Arrays.toString (data)); Radixsort (data,10,4); System.out.println ("After sorting: \ n" + java.util.Arrays.toString (data));}}

  

Java Cardinality Ordering

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.