我收到错误
在 BinarySearchTree.jack(第 20 行)中:在子例程中插入:预期(
在 BinarySearchTree.jack(第 25 行)中:在子例程中插入:预期(我有 2 个类,节点:
class Node {
field int key;
field Node left, right;
constructor Node new(int data){
let key = data;
let left = null;
let right = null;
return this;
}
method int getKey() { return key; }
method Node getLeft() { return left; }
method Node getRight() { return right; }
method void setKey(int _key) {let key=_key; return;}
method void setLeft(Node _left) {let left=_left; return;}
method void setRight(Node _right) {let right=_right; return;}
}
和 BinarySearchTree:
class BinarySearchTree {
field Node root;
constructor BinarySearchTree new() {
let root = null;
return this;
}
method void insertBST(int num) {
let root = BinarySearchTree.insert(num,root);
return;
}
method Node insert(int num,Node p) {
var Node tempNode;
if (p = null){
let p = Node.new(num);
return p;
}
if (num < p.getKey()){
let tempNode = BinarySearchTree.insert(num,p.left);
do p.setLeft(tempNode);
return p;
}
if (num > p.getKey()){
let tempNode= BinarySearchTree.insert(num,p.right);
do p.setRight(tempNode);
return p;
}
do Output.printString("Item in tree and not inserted.");
return p;
}
}
我该如何解决这个错误?