| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:关于二叉树的问题
取消只看楼主 加入收藏
zhangbin55661
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-4-6
结帖率:0
收藏
 问题点数:0 回复次数:0 
关于二叉树的问题
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);
       }

}

这段程序编译通过了,但执行就找不到入口不知道是什么原因?
高手指点一下!!
搜索更多相关主题的帖子: 二叉树 
2009-10-05 10:22
快速回复:关于二叉树的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015607 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved