第章_树和二叉树.ppt

  1. 1、本文档共114页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第章_树和二叉树.ppt

- + / a × e f b - c d NULL NULL 中序遍历结果:a + b × c - d - e / f 中序线索二叉树 Exercise 6-4 试画出如下二叉树的先序线索二叉树和后序线索二叉树 - + / a × e f b - c d - 0 0 / 0 0 + 0 0 e a × 0 0 f b - 0 0 c d 1 1 1 1 1 1 1 1 1 1 0 1 1 1 thrt 中序线索链表 二叉树的二叉线索存储表示 typedef enum PointerTag {Link,Thread}; typedef struct BiThrNode { TElemType data; struct BiThrNode *lchild,*rchild; PointerTag LTag,RTag; }BiThrNode,*BiThrTree; BiThrTree PostNode_InThr(BiThrTree p) { BiThrTree post; post = p->rchild; if(p->RTag = = 0) while(post->LTag = = 0) post = post->lchild; return post; } 左子树 右子树 在中序线索二叉树上寻找任意结点的中序后继结点 左子树 右子树 Exercise 6-5 完成如下算法: 在中序线索二叉树上寻找任意结点的中序前驱结点 BiThrTree PreNode_InThr(BiThrTree p) 在先序线索二叉树上寻找任意结点的先序后继结点 BiThrTree PostNode_PreThr(BiThrTree p) 在后序线索二叉树上寻找任意结点的后序前驱结点 BiThrTree PreNode_PostThr(BiThrTree p) 在中序线索二叉树上寻找任意结点的中序前驱结点 左子树 右子树 BiThrTree PreNode_InThr(BiThrTree p) { BiThrTree pre; pre = p->lchild; if(p->LTag == 0) while(pre->RTag == 0) pre = pre->rchild; return pre; } 左子树 右子树 6.4 树和森林 一.树的存储结构 1.双亲表示法 R B A F G H E D K C –1 0 0 0 1 1 3 6 6 6 R A B C D E F G 0 1 2 3 4 5 6 7 H 8 K 9 树的双亲链表存储表示 #define MAX_TREE_SIZE 100 typedef struct PTNode { TElemType data; int parent; }PTNode; typedef struct { PTNode nodes[MAX_TREE_SIZE]; int r,n; }PTree; 2.孩子表示法 data child1 child2 … childd Exercise 6-6 试证明:在一棵有 n 个结点的度为 k 的树中,有 n(k – 1) + 1 个空链域 data degree child1 child2 … childd - R B A F G H E D K C A B C D R E F G 0 1 2 3 4 5 6 7 H 8 K 9 ∧ ∧ ∧ ∧ ∧ ∧ 0 2 ∧ 1 3 5 ∧ 6 ∧ 7 9 ∧ 8 孩子链表 树的孩子链表存储表示 #define MAX_TREE_SIZE 100 typedef struct CTNode { int child; struct CTNode *next; }*ChildPtr; typedef struct { TElemType data; ChildPtr firstchild; }CTBox; typedef struct { CTBox nodes[MAX_TREE_SIZE]; int n,r; }CTree; A B C D R E F G 0 1 2 3 4 5 6 7 H 8 K 9 ∧ ∧ ∧ ∧ ∧ ∧ 0 2 ∧ 1 3 5 ∧ 6 ∧ 7 9 ∧ 8 R B A F G H E D K C A B C D R E F G 0 1 2 3 4 5 6 7 H 8 K 9 ∧ ∧ ∧ ∧ ∧ ∧ 0 2 ∧ 1 3 5 ∧ 6 ∧ 7 9 ∧ 8 带双亲的孩子链表 4 4 4 –1 0 0 2 6 6 6 3.孩子兄弟表示法 又称二叉树表示法,或二叉链表表示法。即以二叉链表作树的存储结构 

文档评论(0)

czy2014 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档