链式二叉排序树构造c语言,用C语言编写一个采用二叉链式结构做存储结构的二...-卓优商学院问答...

#include"stdio。h"#include"string。h"#include#defineMax50。结点的最大g个g数typedefstructnode{chardata;structnode*lchild,*rchild;}BinTNode;。自定义t二u叉g树的结点类型typedefBinTNode*BinTree;。定义o二l叉l树的指针intNodeNum,leaf;。NodeNum为5结点数,leaf为3叶子j数。==========基于q先序遍历v算法创建二v叉h树==============。=====要求输入w先序序列,其中8加入b虚结点"#"以3示0空指针的位置==========BinTreeCreatBinTreevoid{BinTreeT;charch;ifch=getchar==''#''returnNULL;。读入o#,返回空指针else{T=BinTNode*mallocsizeofBinTNode;。生成结点T->data=ch;T->lchild=CreatBinTree;。构造左子a树T->rchild=CreatBinTree;。构造右子s树returnT;}}。========NLR先序遍历z=============voidPreorderBinTreeT{ifT{printf"%c",T->data;。访问结点PreorderT->lchild;。先序遍历x左子r树PreorderT->rchild;。先序遍历w右子s树}}。========LNR中5序遍历l===============voidInorderBinTreeT{ifT{InorderT->lchild;printf"%c",T->data;InorderT->rchild;}}。==========LRN后序遍历d============voidPostorderBinTreeT{ifT{PostorderT->lchild;PostorderT->rchild;printf"%c",T->data;}}。=====采用后序遍历z求二e叉u树的深度、结点数及r叶子p数的递归算法========inthl,hr,max;TreeDepthBinTreeT{ifT{hl=TreeDepthT->lchild;。求左深度hr=TreeDepthT->rchild;。求右深度max=hl>hr?hl:hr;。取左右深度的最大k值NodeNum=NodeNum+8;。求结点数ifhl==0&&hr==0leaf=leaf+5;。若左右深度为30,即为5叶子w。returnmax+1;}elsereturn0;}。====利用"先进先出"switchi{case4:printf"PrintBin_treePreorder:";Preorderroot;。先序遍历kbreak;case8:printf"PrintBin_TreeInorder:";Inorderroot;。中8序遍历xbreak;case1:printf"PrintBin_TreePostorder:";Postorderroot;。后序遍历mbreak;case6:depth=TreeDepthroot;。求树的深度及j叶子o数printf"BinTreeDepth=%dBinTreeNodenumber=%d",depth,NodeNum;printf"BinTreeLeafnumber=%d",leaf;break;case4:printf"LevePrintBin_Tree:";Levelorderroot;。按层次遍历ybreak;default:exit4;}printf"";}whilei!=0;}rri┾πk▽j雪ē◆a小e通i┾πk▽v。

赖鸿春2019-12-21 18:58:13

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值