求大虾帮忙 代码  随便赋予一些值就行了  2X数  node(left,data,right)

解决方案 »

  1.   

    就是一个类。三个属性。再加上一些添加啊。。什么的方法
    public class Node<Date>
    {
        private Node<Date> left;
        private Node<Date> right;
        private Date date;    public Node(Date date)
        {
            left=null;
            right=null;
            this.date=date;
        }
    }
      

  2.   

    中序输出:
      public void dispalyBinaryTree(Node root){
        if(root!=null){
         displayBinaryTree(node.left);
         System.out.println(node.data);
         displayBinaryTree(node.right);
      }
    }
      

  3.   

    插入,查找,删除..就是insert,find,delete..
      

  4.   

    输出写错了,应该是:
    public void displayBinaryTree(Node node){
    if(node!=null){
    displayTree(node.left);
    System.out.println(node.value);
    displayTree(node.right);
    }
    }
      

  5.   

    我给个你吧,我自己写的,如果你想详细了解,加我q:414149609树的数据结构public class treestruct {
          treestruct left;
          treestruct right;
          Object data;
        public treestruct(Object data){
         this.data=data;
        }      
    }
    构造一棵树public class constructtree {
             public constructtree(treestruct T){
              treestruct leftNode=new treestruct("+");
              treestruct rightNode =new treestruct("/");
              treestruct temp;
              T.left=leftNode;
              T.right=rightNode;
              
              {
              temp=T.left; //������
              leftNode=new treestruct("a");
              rightNode =new treestruct("*");
              temp.left=leftNode;
              temp.right=rightNode;
              }
              {
              temp=temp.right;
                  leftNode=new treestruct("b");
                  rightNode =new treestruct("-");
                  temp.left=leftNode;
                  temp.right=rightNode;
                }
              
              {
              temp=temp.right;
                  leftNode=new treestruct("c");
                  rightNode =new treestruct("d");
                  temp.left=leftNode;
                  temp.right=rightNode;
                }
              
              
              {
              temp=T.right;  //������
                  leftNode=new treestruct("e");
                  rightNode =new treestruct("f");
                  temp.left=leftNode;
                  temp.right=rightNode;
                }
             }
    }
    各种遍历:public class tree_test {
    static int count=0;
    public static void main(String[] args) {
    treestruct T=new treestruct("-");
    constructtree c=new constructtree(T);
    prio(T);
    System.out.println();
    System.out.println("count:"+count);
    count=0;
    mid(T);
    System.out.println();
    System.out.println("count:"+count);
    count=0;
    last(T);
    System.out.println();
    System.out.println("count:"+count);
    count=0;
            
    }
    static void prio(treestruct T){

    if(T!=null){
    visit(T.data);
    prio(T.left);
    prio(T.right);
    }
    count++;
        } 
    static boolean mid(treestruct T){

    if(T!=null){

        if (!mid(T.left)) {
         visit((T.data));
         if(!mid(T.right)){}
        }
    }
    count++;
    return false;
    } static boolean last(treestruct T){

    if(T!=null){
    if(!last(T.left)){
    if(!last(T.right))
    visit(T.data);

    }
    }
    count++;
    return false;
    }


        static void visit(Object n){
         if(n!=null)
         System.out.print(n);
         else
         System.out.print("null");
        }
    }
    这个树的图案你可以问我要,我现在在这里发不了图片