PackageCom.edu.hpu.sort.radix;Importjava.util.LinkedList;Importjava.util.List;ImportCom.edu.hpu.sort.Sort; Public classRadixsortextendsSort {Private intRadix; Private intD; PublicRadixsort (intRadixintd) { This. Radix =Radix; This, db=D; } @Override Public int[] Dosort (int[] arr) {List<integer>[] Bucket =init (radix); int[] tmp =New int[Arr.length]; //control the bit of the number for(inti = 0; I < D; i++){ //gets the number of bits per digit of one for(intV:arr) { intD = (int) (V/math.pow (ten, i)% 10); Bucket[d].add (v); } //The results of each bit being sorted into the TMP for(intw = 0, j = 0; J < Bucket.length && W < tmp.length; J + +){ for(intV:bucket[j]) {Tmp[w]=v; W++; } } //Working with Arraysarr =tmp; for(list<integer>l:bucket) {l.clear (); } } returnarr; } //Initialize bucket Privatelist<integer> [] Init (intrange) {@SuppressWarnings ("Unchecked") List<Integer> [] aux =NewLinkedlist[range]; for(inti = 0; i < aux.length; i++) {Aux[i]=NewLinkedlist<integer>(); } returnaux; } Public Static voidMain (string[] args) {sort sort=NewRadixsort (10, 3); Sort.printorder (New int[]{4, 1, 3, 2, 16, 101, 43,200,999, 9, 100, 194, 8, 7}); }}
Java implementations of cardinality ordering