示例#1
0
int PostTreeDepth(BitTree bt)   //后序遍历求二叉树的高度递归算法//
{
 int hl,hr,max;
 if(bt!=NULL)
 {
  hl=PostTreeDepth(bt->LChild);  //求左子树的深度 
  hr=PostTreeDepth(bt->RChild);  //求右子树的深度 
  max=hl>hr?hl:hr;              //得到左、右子树深度较大者
  return(max+1);               //返回树的深度
 }
 else return(0);              //如果是空树,则返回0
}
示例#2
0
//后序遍历求二叉树深度算法
int PostTreeDepth(BTree root)
{
    int leftheight,rightheight,max;
    if(root!=NULL)
    {
        leftheight=PostTreeDepth(root->LChild);
        rightheight=PostTreeDepth(root->RChild);
        max=leftheight>rightheight?leftheight:rightheight;
        return(max+1);
    }
    else
        return 0;
}
示例#3
0
int PostTreeDepth (BiTree  * root)
{
	int hl ,hr, h;

	if (root == NULL)
	{
		return 0;
	}

	else
	{
		hl = PostTreeDepth(root->Lchild);
		hr = PostTreeDepth(root->Rchild);

		h = (hl > hr ? hl : hr) + 1;
		return h;
	}
}
示例#4
0
void main()
{
 BitTree T;
 int h;
 int layer;
 int treeleaf;
 layer=0;
 printf("请输入二叉树中的元素(以扩展先序遍历序列输入,其中.代表空子树):\n");
    CreatBiTree(&T);
 printf("先序遍历序列为:");
 PreOrder(T);
 printf("\n中序遍历序列为:");
 InOrder(T);
 printf("\n后序遍历序列为:");
 PostOrder(T);
 h=PostTreeDepth(T);
    printf("\nThe depth of this tree is:%d\n",h);
 PrintTree(T,layer);
}