You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.

View previous topic View next topic Go down

You are given a TreeNode, and you have to write an algorithm which will return the no. of nodes in the tree.

Post  skyboard on Sat Sep 03, 2011 4:41 pm

public static getNumber(TreeNode root){
if(root==null)
return 0;
return (getNumber(root.getleft())+getNumber(root.getright())+1);
}

skyboard

Posts : 31
Join date : 2011-09-03

View user profile

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