关于二叉树的问题
public class Tree{Node pera;
//Node pera1=new Node();
//建树
public Node creattree(Node b,int a){
if(pera==null){
return (new Node(a));
}else if(a>=pera.data){
pera.right=creattree(pera.right,a);
return pera;
}else{
pera.left=creattree(pera.left,a);
return pera;
}
//return pera;
}
//遍历
public void treeout(Node pera1){
if(pera==null)
return;
System.out.println(pera.data);
treeout(pera.left);
treeout(pera.right);
}
//查找
public boolean chazhao(Node pera,int a){
boolean k=false;
if(pera.data==a)
k=true;
chazhao(pera.left,a);
chazhao(pera.right,a);
return k;
}
//计算高度
public int leaves(){
int leaveno;
if(pera==null)
return -1;
int leaveleft=(pera.left==null?0:leaves());
int leaveright=(pera.right==null?0:leaves());
leaveno=(leaveleft<leaveright)?leaveleft:leaveright;
return leaveno;
}
}
class Node{
int data;
Node left,right;
public Node(){
data=0;
left=right=null;
}
public Node(int data){
this.data=data;
left=right=null;
}
}
class text1{
public static void main(String[] arge){
Tree B=new Tree();
//Tree C=new Tree();
for(int i=1;i<5;i++){
Node A=new Node(i);
B.creattree(A,i);
}
B.treeout(B.pera);
boolean k=B.chazhao(B.pera,4);
int a=B.leaves();
System.out.println(a);
System.out.println(k);
}
}
这段程序编译通过了,但执行就找不到入口不知道是什么原因?
高手指点一下!!