Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Find the height of BST

Go down

Find the height of BST Empty Find the height of BST

Post  Admin 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

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

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