question about LSD radix sort
Posted
by davit-datuashvili
on Stack Overflow
See other posts from Stack Overflow
or by davit-datuashvili
Published on 2010-05-31T06:28:35Z
Indexed on
2010/05/31
6:32 UTC
Read the original article
Hit count: 269
algorithm
hello i have following code
public class LSD{
public static int R=1<<8;
public static int bytesword=4;
public static void radixLSD(int a[],int l,int r){
int aux[]=new int[a.length];
for (int d=bytesword-1;d>=0;d--){
int i, j;
int count[]=new int[R+1];
for ( j=0;j<R;j++) count[j]=0;
for (i=l;i<=r;i++)
count[digit(a[i],d)+1]++;
for (j=1;j<R;j++)
count[j]+=count[j-1];
for (i=l;i<=r;i++)
aux[count[digit(a[i],d)]++]=a[i];
for (i=l;i<=r;i++)
a[i]=aux[i-1];
}
}
public static void main(String[]args){
int a[]=new int[]{3,6,5,7,4,8,9};
radixLSD(a,0,a.length-1);
for (int i=0;i<a.length;i++){
System.out.println(a[i]);
}
}
public static int digit(int n,int d){
return (n>>d)&1;
}
}
but it show me mistake
java.lang.ArrayIndexOutOfBoundsException: -1
at LSD.radixLSD(LSD.java:19)
at LSD.main(LSD.java:29)
please help me
© Stack Overflow or respective owner