class nodekey
{
int data;
nodekey left;
nodekey right;
public nodekey(int d)
{
data=d;
}
public void print()
{
System.out.println("Data: "+data);
}
}
class tree
{
nodekey root;
public tree()
{
root=null;
}
public void insert(int key)
{
nodekey newnode=new nodekey(key);

if(root==null)
root=newnode;
else
{
nodekey parent=null;
nodekey cur=root;
while(true)
{
parent=cur;
if(key<cur.data)
{
cur=cur.left;
if(cur==null)
{
parent.left=newnode;
return;
}
}
else
{
cur=cur.right;
if(cur==null)
{
parent.right=newnode;
return ;
}
}
}
}
}
public void preorder(nodekey root)
{
if(root!=null)
root.print();
preorder(root.left);
preorder(root.right);
}
public void disp()
{
preorder(root);
}
}
class quiz
{
public static void main(String[] args)
{
tree tr=new tree();
tr.insert(4);
tr.insert(3);
tr.insert(5);
tr.disp();

}
}
只显示4和3,不显示5,怎么办呢,帮忙修改一下啊!