我正在尝试实现二叉树类。这是插入方法。当我编译它时,我得到一个错误,因为"使用未经检查或不安全的操作。使用-Xlint编译:unchecked有关详情" 。
有人可以告诉我如何纠正这个问题吗?
public class BinaryNode{
Comparable element;
BinaryNode left;
BinaryNode right;
BinaryNode(Comparable theElement,BinaryNode lt,BinaryNode rt){
element=theElement;
left=lt;
right=rt;
}
BinaryNode(Comparable theElement){
this(theElement,null,null);
}
}
public class BinaryTr {
private BinaryNode root;
BinaryTr(){
root=null;
}
public void insert(Comparable x){
root=insert(root,x);
}
public BinaryNode insert(BinaryNode current,Comparable x){
if (current==null)
current=new BinaryNode(x);
else{
if(current.element.compareTo(x)>0)
current.left=insert(current.left,x);
else if (current.element.compareTo(x)<0)
current.right=insert(current.right,x);
else{
System.out.println("Duplicates not allowed");
}
}
return current;
}
public static void main (String args[]){
BinaryTr t=new BinaryTr();
t.insert(5);
t.insert(4);
t.insert(5);
}
}