0

hi i have write LSD radix sort but it does not work can anybody help me?
here is 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];
   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);

 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;

}
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by jwenting
0

sorry, LSD is so 1960s :)

"does not work" doesn't tell us anything. Be more specific, a lot more specific.
And please correct your code tags, you tried to use them but I think you forgot the close tag.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.