Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Radix Sort in descending order

807606Apr 7 2007 — edited Apr 12 2007
I am having a really hard time changing the radix sort code so that it can sort in descending order. Can anyone please recode this:


//Radix Sort Execution Sort
public int[] executeSort(int[] arr)
{
Vector[] holes = new Vector[numberOfPossibleDigits];
int[] arrTemp = new int[arr.length];
int a=0;
while(a<arr.length)
{
arrTemp[a]=arr[a];
a++;
}

for (int i=0;i<numberOfPossibleDigits;i++)
{
holes[i] = new Vector();
}

for (int i=0;i<arrTemp.length;i++)
{
int divisor=(int)Math.pow(numberOfPossibleDigits,i);
for (int j=0;j<arrTemp.length;j++) //Ascending
{
holes[(arrTemp[j]/divisor)%numberOfPossibleDigits].
addElement(new Integer(arrTemp[j]));
}

int index=0;

for(int j=0;j<numberOfPossibleDigits;j++)
{
for(int k=0;k<holes[j].size();k++)
{
arrTemp[index]=((Integer)(holes[j].elementAt(k))).intValue();
index++;
}
holes[j].removeAllElements();
}

}
return arrTemp;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 10 2007
Added on Apr 7 2007
21 comments
2,113 views