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

时间:2014-01-16 06:03:52
【文件属性】:
文件名称:二叉树递归的实现前序 中序 后序遍历
文件大小:30KB
文件格式:DOC
更新时间:2014-01-16 06:03:52
中序 前序 后序遍历 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;idata); PrintTree(Boot->LChild,nLayer+1); }

网友评论