正在加载图片...
644编写递归算法,求三叉树中以元素值为x的结点为根的子树的 深度。 int dep( BiTree*r; Elem Type x,int*h)∥根据后根遍历 i int h1, h2 if( T) f hl=dep(t->lchild, x, h); h2=dep(t->rchild, x, h) if (T->data==)*h=h1h2? h1+1: h2+ return hI>h2? h1+1: h2+1 main i hight=0: de lep(root, x, &hight6.44 编写递归算法,求二叉树中以元素值为x的结点为根的子树的 深度。 int dep(BiTree *T,ElemType x, int *h) //根据后根遍历 { int h1,h2; if (T) { h1=dep(T->lchild , x , h); h2=dep(T->rchild ,x , h); if (T->data==x) *h=h1>h2? h1+1 :h2+1; return h1>h2? h1+1 :h2+1; } main() { hight=0; dep(root,x,&hight);
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有