函数接口定义: intdepth(bitreet ); t是二叉树根的指针,函数Depth返回二叉树的深度,如果树为空则返回0。
审判程序示例: # include stdio.h # include stdlib.htypedefcharelemtype; typedefstructbitnode { elemtype data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; BiTree Create (; /*此处不提供详细信息。 */intdepth(bitreet ); int main () {BiTree T=Create ); printf(%d(n ),Depth(T ) t ); 返回0; }/*你的代码嵌入在这里。 */二叉树的深度是树中节点的最大层次,左右子树深度较大者1;
空树深0;
intdepth(bitreet ) if ) t==null { return 0; }else{if(depth(t-lchild ) depth (t-rchild ) ) return (repth ) depth (t-lchild )1); else return (深度(t-rchild ) 1; }