我正在尝试使用一系列队列进行基数排序,以避免长时间漫无目的切换语句,但是我在使数组正确初始化时遇到了一些麻烦。下面给出构造函数和实现的示例。
当我尝试编译时,我只是找不到符号错误。
public static radixj(){
IntQueue[] buckets = new IntQueue[10];
for (int i = 0; i < 10; i++)
buckets[i] = new IntQueue();
}
public static void place(int temp, int marker)
{
int pos = temp % marker;
buckets[pos].put(temp);
}
我很确定这是一个非常简单的错误,我正在制作,但我找不到它。任何帮助将不胜感激。
答案 0 :(得分:3)
在您的代码中
IntQueue[] buckets = new IntQueue[10];
是函数的局部变量
public static radixj()
必须有返回类型
public static void radixj()
那么你就不能在另一个函数中使用它
buckets[pos].put(temp);
你应该声明一个静态类变量
class Foo {
static IntQueue[] buckets = new IntQueue[10];
...
并使用:Foo.buckets
class Foo {
public static IntQueue[] buckets = new IntQueue[10];
public static void radixj() {
for (int i = 0; i < 10; i++) {
Foo.buckets[i] = new IntQueue();
}
}
public static void place(int temp, int marker) {
int pos = temp % marker;
Foo.buckets[pos].put(temp);
}
}
答案 1 :(得分:1)
radixj()
中的返回类型丢失,buckets
无法解析为变量