Java树 - 我想知道我的答案是否正确

时间:2014-02-04 16:33:16

标签: java

我有这个实现树的类:

public class Node
{
   private int _number;
   private Node _leftSon, _rightSon;

   public Node (int number)
   {
      _number = number;
      _leftSon = null;
      _rightSon = null;
   }
   public int getNumber()
      {return _number; }
   public Node getLeftSon()
      {return _leftSon; }
   public Node getRightSon()
      {return _rightSon; }
}

这个功能:

public static int f (int a, int b)
{
   return (a>b) ? a:b;
}

public static int what (Node root)
{
   if (root == null)
      return -1;
   return (f (what (root.getLeftSon()), what (root.getRightSon())) +1);
}

此功能将通过以下树返回:

http://s7.postimg.org/cuh1i6eij/123.png

我的结果是4但我不知道这是否是正确的答案,另一件事是我没有找到这个功能正在做什么

0 个答案:

没有答案