- 29
- 0
- 约1.33千字
- 约 3页
- 2017-06-07 发布于重庆
- 举报
《数据结构》树的基本操作
实验四
课程名称: 完成日期: 姓名:学号:指导教师: 实验名称: 实验序号: 实验成绩: 一、实验目的及要求
二、实验环境、实验内容
求出它的深度。
、调试过程及实验结果
五、总结、附录(源程序清单)#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
您可能关注的文档
最近下载
- 2022年注册土木工程师(道路工程)《专业案例考试(下)》真题及答案解析.docx VIP
- 2025年辽宁省交通高等专科学校单招《数学》测试卷带答案详解(基础题).docx VIP
- 中国肺血栓栓塞症诊治、预防和管理指南(2025版)解读.pptx
- 版上市公司行业分类申万.pdf VIP
- GB_T28043-2019利用实验室间比对进行能力验证的统计方法.docx VIP
- 职业技能鉴定考试《电梯安装维修工高级》全真试题及答案.docx VIP
- 2025年辽宁省交通高等专科学校单招语文测试试卷题型大全.docx VIP
- 标准图集-22G101-3 混凝土结构施工图平面整体表示方法制图规则和构造详图-独立基础、条形基础、筏形基础、桩基础.pdf VIP
- 中考数学总复习《一次函数中角度问题》专项检测卷(含答案).docx VIP
- 汽车零件质量分析案例.pptx VIP
原创力文档

文档评论(0)