优先级队列实现堆
Priority Queue implemented Heap
你好所以我想做一个优先队列实现堆按降序排列,从大到小,我想用指数来实现。所以我完成了我的堆和优先级队列 classes,但是现在在制作我的 class 时我收到一条错误消息说
xponents.java:66: error: invalid method declaration; return type required
public Exponent(int num, int exponent, int x)
我不确定我哪里出错了
public class Exponents implements Comparable<Exponents>
{
private int num;
private int exponent;
private int x;
public Exponents(int num, int exponent, int x)
{
this.num = num;
this.exponent = exponent;
this.x = x;
}
public int Answer()
{
int x = Math.pow(num,exponent);
return x;
}
public String toString()
{
String s = ("Exponent: " + exponent + "\n Number: "+ num + "\nYour x is: )" + x);
return s;
}
public int compareTo(Answer e)
{
return this.x - o.x;
}
}
由于打字错误问题已解决,现在我收到更多错误,我不太确定我写错了什么:
Exponents.java:83: error: cannot find symbol
public int compareTo(Answer e)
^
symbol: class Answer
location: class Exponents
Exponents.java:74: error: incompatible types: possible lossy conversion from double to int
int x = Math.pow(num,exponent);
^
Exponents.java:85: error: cannot find symbol
return this.x - o.x;
^
symbol: variable o
location: class Exponents
3 errors
您的构造函数中有错字。您的 class 被命名为 Exponents
但在您的构造函数中,它显示为 Exponent
。它成为无效的方法声明,因为它正在寻找 return 数据类型,因为您创建的 'constructor' 的名称与 class.[=15= 的名称不同]
编辑:
- 您没有 class 名字
Answer
。
- 您不能将 double 隐式转换为 int。您可以使用
Math.pow(num,exponent).intValue()
- 您在方法或 class 的范围内没有名为
o
的变量。
你好所以我想做一个优先队列实现堆按降序排列,从大到小,我想用指数来实现。所以我完成了我的堆和优先级队列 classes,但是现在在制作我的 class 时我收到一条错误消息说
xponents.java:66: error: invalid method declaration; return type required
public Exponent(int num, int exponent, int x)
我不确定我哪里出错了
public class Exponents implements Comparable<Exponents>
{
private int num;
private int exponent;
private int x;
public Exponents(int num, int exponent, int x)
{
this.num = num;
this.exponent = exponent;
this.x = x;
}
public int Answer()
{
int x = Math.pow(num,exponent);
return x;
}
public String toString()
{
String s = ("Exponent: " + exponent + "\n Number: "+ num + "\nYour x is: )" + x);
return s;
}
public int compareTo(Answer e)
{
return this.x - o.x;
}
}
由于打字错误问题已解决,现在我收到更多错误,我不太确定我写错了什么:
Exponents.java:83: error: cannot find symbol
public int compareTo(Answer e)
^
symbol: class Answer
location: class Exponents
Exponents.java:74: error: incompatible types: possible lossy conversion from double to int
int x = Math.pow(num,exponent);
^
Exponents.java:85: error: cannot find symbol
return this.x - o.x;
^
symbol: variable o
location: class Exponents
3 errors
您的构造函数中有错字。您的 class 被命名为 Exponents
但在您的构造函数中,它显示为 Exponent
。它成为无效的方法声明,因为它正在寻找 return 数据类型,因为您创建的 'constructor' 的名称与 class.[=15= 的名称不同]
编辑:
- 您没有 class 名字
Answer
。 - 您不能将 double 隐式转换为 int。您可以使用
Math.pow(num,exponent).intValue()
- 您在方法或 class 的范围内没有名为
o
的变量。