到目前为止,我一直在编写一个名为Node的类
class Node {
private value;
private Node left;
private Node right;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public Node getLeft() {
return left;
}
public void setLeft(Node left) {
this.left = left;
}
public Node getRight() {
return right;
}
public void setRight(Node right) {
this.right = right;
}
}
二叉搜索树
public class BinarySearchTree {
private Node root;
public BinarySearchTree(int value) {
root = new Node(value);
}
public void insert(int value) {
Node node = new Node(value);
// insert logic goes here to search and insert
}
}
现在我想要支持BinarySearchTree插入任何类型的节点,例如字符串、人员对象等。
我该如何将它变成通用型,以容纳任何类型的节点?