I am trying to implement a Binary Tree class.Here's the insert method.When I compile it I get an error as "uses unchecked or unsafe operations.Recompile with -Xlint:unchecked for details".
Can some on please tell me how I can correct this?
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);
}
}