• 二叉树递归的实现前序 中序 后序遍历

    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 } void PrintTree(BitTree Boot,int nLayer) //按竖向树状打印的二叉树 // { int i; if(Boot==NULL) return; PrintTree(Boot->RChild,nLayer+1); for(i=0;i<nLayer;i++) printf(" "); printf("%c\n",Boot->data); PrintTree(Boot->LChild,nLayer+1); }

    0
    109
    30KB
    2010-12-27
    9
关注 私信
上传资源赚积分or赚钱