teleias

Java: How to Assign Node Height

Oct 20th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.22 KB | None | 0 0
  1.     public static int assignHeight(node n)
  2.     {
  3.         if(n == null)
  4.         {
  5.             return -1;
  6.         }
  7.         int hL;
  8.         int hR;
  9.         hL = assignHeight(n.left)+1;
  10.         hR = assignHeight(n.right)+1;
  11.         n.height = Math.max(hL, hR);
  12.         return n.height;
  13.     }
Advertisement
Add Comment
Please, Sign In to add comment