我曾尝试为Radix排序编写代码但我得到Null Pointer Exception。虽然我试图干掉它,并采取必要的行动。
public class RadixSort
{
public static void main(String arg[])
{
int a[] = {74, 68, 20, 231, 29, 44};
StandardQueue Q[] = new StandardQueue[10];
int div = 1;
int t;
int num = max(a);//Gets Largerst Number
int c = 0;
while(num > 0)
{
c++;
num /= 10;
}
for(int p = 1; p <= c; p++)
{
for(int i = 0; i < a.length; i++)
{
t = a[i] / div % 10;
**Q[t].enQueue(a[i]);** //This Gives Null Pointer
}
}
}
}