所以我正在为二叉搜索树编写代码并且我很远(我认为)并且有一点当我尝试编译它时我得到一个错误说
“文件:D:\ReservationQueue.java [行:15]
错误:left 无法解析或不是字段
文件:D:\ReservationQueue.java [行:17]
错误:权限无法解析或不是字段
文件:D:\ReservationQueue.java [行:4] 警告:永远不会在本地读取字段 ReservationQueue.right...
这是错误的代码,
public class ReservationQueue{
private Reservation root;
private Reservation left;
private Reservation right;
public boolean empty() {return root == null;}
public String findRoot() {return root.getName();}
public void deleteRoot(){root = left; }
public void insert(Reservation node) {
if(this.empty()) {
root = node;
} else if (node.getPriority() < root.getPriority()){
insert(node.left);
} else if (node.getPriority() > root.getPriority()){
insert(node.right);
}
}
}
如果它有助于 public class Reservation{ private int priority; 这就是 Reservation 类 私有字符串名称;
public Reservation(String name, int priority){
if (priority < 1) {
this.priority = 1;
} else if (priority > 10) {
this.priority = 10;
} else {
this.priority = priority;
}
}
public String getName(){return name;}
public int getPriority(){return priority;}
}
我真的需要帮助我不知道我做错了什么,提前谢谢你