二叉树遍历算法应用分析.pptVIP

  • 17
  • 0
  • 约8.22千字
  • 约 35页
  • 2016-06-07 发布于安徽
  • 举报
6.3.5 二叉树遍历算法的应用 1. 统计二叉树中结点总数numb 假设用中根遍历方法统计结点总个数,设计一个公有函数作为对外接口,调用同名的私有递归函数实现此功能。 //公有函数 void BiTree::injishu() { int numb=0; injishu( root, int numb); // 调用私有函数 cout\n numb=numb ; // 输出结果 } 算法 6.8 //私有函数 void BiTree::injishu(NodeType *t, int m) { if (t!=NULL) { injishu(t-lch,m); // 中根遍历左子树 coutt-data” ”; // 访问根结点 m++; // 结点记数 injishu(t-rch,m); // 中根遍历右子树 }} 2.求二叉树的树深 首先看如下算法: int BiTree::height(NodeType *p)

文档评论(0)

1亿VIP精品文档

相关文档