public class RadixAlgorithm { //There are some attributes that you may not have to use in this class, but I declared //them because I'll use them in the solution class. private final int howManyDigit = 10; //This is the number of digits of the set of usigned integers. (2^32 = 4294967296) private int howManyNumber = 10; //Initial size of the array. private String[] st; private myList mList; private myQueueString[] radQ = new myQueueString[11]; //The array radQ has 11 //queues: 10 to store the first 10 significant digit (from 0-9) and the extra queue to store the sorted queue. public RadixAlgorithm(){} public RadixAlgorithm(String[] stArray){ this.st = stArray; this.howManyNumber = stArray.length; } //Array sort method using Radix Algorithm. public void processRadixAlgoritm(String[] stArray){ this.st = stArray; this.howManyNumber = stArray.length; for(int i = 0; i < 11; i++) radQ[i] = new myQueueString(this.howManyNumber + 1);//just make sure that the size of the queue is one more than //the size of the array so that the queue can store all the elements in the array. for(int i = 0; i < this.howManyNumber; i++) //add zero(es) in front of the integers if the st[i] = prependZero(st[i], howManyDigit); //number of the digit of this integer is < howmanyDigit. for(int i = 0; i < howManyNumber; i++)//enqueue the integers into the sorted queue then resort his queue. radQ[10].enQueue(st[i]); String tmp = ""; for(int j = 1; j <= this.howManyDigit; j++){//Outer loop: loop thru all the digits. for(int i = 0; i < this.howManyNumber; i++){ //Inner loop: loop thru all the characters of the string. tmp = radQ[10].deQueue(); if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("0")==0) radQ[0].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("1")==0) radQ[1].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("2")==0) radQ[2].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("3")==0) radQ[3].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("4")==0) radQ[4].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("5")==0) radQ[5].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("6")==0) radQ[6].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("7")==0) radQ[7].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("8")==0) radQ[8].enQueue(tmp); else if(tmp.valueOf(tmp.charAt(tmp.length() - j)).compareTo("9")==0) radQ[9].enQueue(tmp); }//end of inner FOR() enQueueRadQ(); //enqueue the integer into the sorted queue. } //end of outer FOR() int index = 0; //index of the original array. while(! radQ[10].isEmpty()){ //re-assigned the elements of the array so that all elements are in sorted order. stArray[index] = removeLeadingZero(radQ[10].deQueue()); index++; } }//end of method //Enqueue the elements in each of the queue (from queue[0] to queue[9]) to the sorted queue (queue[10]). public void enQueueRadQ(){ while(! radQ[0].isEmpty()) radQ[10].enQueue(radQ[0].deQueue()); while(! radQ[1].isEmpty()) radQ[10].enQueue(radQ[1].deQueue()); while(! radQ[2].isEmpty()) radQ[10].enQueue(radQ[2].deQueue()); while(! radQ[3].isEmpty()) radQ[10].enQueue(radQ[3].deQueue()); while(! radQ[4].isEmpty()) radQ[10].enQueue(radQ[4].deQueue()); while(! radQ[5].isEmpty()) radQ[10].enQueue(radQ[5].deQueue()); while(! radQ[6].isEmpty()) radQ[10].enQueue(radQ[6].deQueue()); while(! radQ[7].isEmpty()) radQ[10].enQueue(radQ[7].deQueue()); while(! radQ[8].isEmpty()) radQ[10].enQueue(radQ[8].deQueue()); while(! radQ[9].isEmpty()) radQ[10].enQueue(radQ[9].deQueue()); }//end of method //Add zero(es) to the front of an integer if the number of digit of that integer is //less than the specified digits so that we can scan thru each of the digit then enqueue //it in the right queue. public String prependZero(String st, int howmany){ for(int i = st.length(); i < howmany; i++){ if(st.length() <= howmany) st = "0" + st; } return st; }//end of method. //Remove all leading zeroes from the string of integer. public String removeLeadingZero(String st){ int tmp = Integer.parseInt(st); return String.valueOf(tmp); //return the actual value of the integer without the leading zero(es). }//end of method. }//end of class RadixAlgorithm{}