コード例 #1
0
// Max depth in tree
void
TreeDictionary::computeDepthHelper(TreeNode * node, int depth, int & currentMaxDepth) {
		
		if(node==NULL)
		{
			return;
		}
		
		if(depth>currentMaxDepth){
			currentMaxDepth++;
		}	

		if(node->_left!=NULL||node->_right!=NULL)
		{

		TreeNode * n = node;
			
		
		computeDepthHelper(n->_right,depth+1,currentMaxDepth);
		computeDepthHelper(n->_left,depth+1,currentMaxDepth);
		
		
		}
				

}
コード例 #2
0
ファイル: TreeDictionary.cpp プロジェクト: mihirjham/Purdue
// Max depth in tree
void TreeDictionary::computeDepthHelper(TreeNode * node, int depth, int & currentMaxDepth) {
  if (node==NULL) return;

  if ( node->_left == NULL && node->_right == NULL) {
    // Found a leaf. Update maxDepth and minDepth
    if ( currentMaxDepth == -1 || depth > currentMaxDepth) {
      currentMaxDepth = depth;
    }
  }

  computeDepthHelper(node->_left, depth+1, currentMaxDepth);
  computeDepthHelper(node->_right, depth+1, currentMaxDepth);

  return;
}
コード例 #3
0
ファイル: TreeDictionary.cpp プロジェクト: mihirjham/Purdue
int 
TreeDictionary::maxDepth() {
  int currentMaxDepth = -1;

  computeDepthHelper(_root, 0, currentMaxDepth);

  return currentMaxDepth;
}
コード例 #4
0
int 
TreeDictionary::maxDepth() {

	int cmd = -1;
		
 	computeDepthHelper(_root,0,cmd); 
	
	return cmd;
}