4、(二叉树查找)编写程序给出方法,在一个二叉查找树中找到某一指定的值。方法的参数是查找关键字的值。如果找到了包含关键字的值的点的结点,方法应返回对该结点的引用;否则,方法返回一个空引用。

解决方案 »

  1.   

    public Tree findT(Tree head, Object value){   switch (head.value.compareTo(Value))
          case 1: return findT(head.left, value); 
          case 0: return head;
          case -1: return findT(head.right, value)
    }}
      

  2.   

    public Tree findT(Tree head, Object value){if(head==null) return head;   switch (head.value.compareTo(Value))
          case 1: return findT(head.left, value); 
          case 0: return head;
          case -1: return findT(head.right, value)
    }}