树二叉树树、森林和二叉树的转换树的应用.pptVIP

  • 78
  • 0
  • 约5.48千字
  • 约 57页
  • 2018-08-06 发布于江苏
  • 举报

树二叉树树、森林和二叉树的转换树的应用.ppt

树二叉树树、森林和二叉树的转换树的应用

树 二叉树 树、森林与二叉树的转换 树的应用 例:给定一棵二叉树,输出其嵌套括号表示 void print(bitree *t) { if (t) { printf(“%d”, t-data); if (t-lchild ||t-rchild) { printf(“(”); printf(lchild); if (t-rchild) printf(“,”); print(rchild); printf(“)”); } } } 例:求二叉树的深度 void depth(bitree *t) { int dep1, dep2; if (t = = NULL) return(0); else { dep1 = depth(t-lchild); dep2 = depth(t-rchild); if (dep1 dep2) return(dep1 + 1); else return(dep2 + 1); } } 例:证明:一棵二叉树的前序序列和中序序列可 以唯一的确定这棵二叉树。 用归纳法证明: 1、当 n = 1时,结论显然成立; 2、假定当 n = k 时,结论成立;

文档评论(0)

1亿VIP精品文档

相关文档