Find the height of BST

View previous topic View next topic Go down

Find the height of BST

Post  Admin on Wed Aug 24, 2011 2:34 pm

public int findheight(TreeNode root){
if(root==null)
return 0;
if(!root.left&&root.right)
return 1;
else{
return MAX(findheight(root.left)+1, findheight(root.right)+1);
}
}

public int MAX(int a1, int a2){
if(a1>a2)
return a1;
else if(a1<a2)
return a2;
else
return a1;
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum