二叉树深度

  
  
  
  
  1. 求二叉树的深度,通常使用这种递归算法. 
  2. int GetDepth(Node* root) { 
  3. if (NULL == root) { 
  4.     return 0; 
  5. int left_depth = GetDepth(root->left); 
  6. int right_depth = GetDepth(root->right); 
  7. return left_depth > right_depth ? left_depth + 1 : right_depth + 1; 

 

本文出自 “ni掌柜的IT专栏” 博客,谢绝转载!

你可能感兴趣的:(二叉树,深度)