网站大量收购独家精品文档,联系QQ:2885784924

《数据结构》树的基本操作.doc

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

实验四 课程名称: 完成日期: 姓名:学号:指导教师: 实验名称: 实验序号: 实验成绩: 一、实验目的及要求 二、实验环境、实验内容 求出它的深度。 、调试过程及实验结果 五、总结、附录(源程序清单)#include #include typedef struct CSNode char data; struct CSNode *firstchild, *nextsibling; CSNode, *CSTree; void createtree CSTree T //以二叉树创建树 char ch; ch getchar ; if ch T NULL; else if ! T CSNode * malloc sizeof CSNode printf 分配空间出错! ; T- data ch; createtree T- firstchild ; createtree T- nextsibling ; void visit CSTree T //遍历函数,输出结点 if T printf %c,T- data ; else printf 树不存在,输出错误! ; void preroot CSTree T //先根输出 if T visit T ; preroot T- firstchild ; preroot T- nextsibling ; void postroot CSTree T //后根输出相当于二叉树中序遍历 if T postroot T- firstchild ; visit T ; postroot T- nextsibling ; int n 0; int countleaf CSTree T if T! NULL countleaf T- firstchild ; if T- firstchild NULL n++; countleaf T- nextsibling ; return n; int depth CSTree T int firstdepth,nextdepth; if !T return 0; else firstdepth depth T- firstchild ; nextdepth depth T- nextsibling ; return firstdepth+1 nextdepth?firstdepth+1:nextdepth; int main CSTree T; printf 请输入树的结点,以二叉树的格式创建,空格表示无左右孩子:\n ; createtree T ; printf \n先根输出树的结点:\n ; preroot T ; printf \n后根输出树的结点:\n ; postroot T ; printf \n树的深度是depth %d,depth T ; printf \n树的叶子数目是leaf %d\n,countleaf T ; while 1 ; return 0; 1

文档评论(0)

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

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

1亿VIP精品文档

相关文档