首页 > 编程知识 正文

二叉树的遍历图解例题,在非空二叉树的中序遍历中

时间:2023-05-04 00:35:25 阅读:160329 作者:4902

用扩展的先行路径构造二叉树,根节点的地址用函数值返回。

例如

输入AB#DF##G##C##,如下图所示创建二叉树。

二叉树. png

输出该二叉树的先行遍历序列ABDFGC。

# include stdio.h # include stdlib.htypedefcharelementtype; typedefstructbitnode { elementtypedata; struct BiTNode* lchild; struct BiTNode* rchild; }BiTNode,* BiTree; BiTree CreatBinTree (; voidpreorder(bitreet; int main () { BiTree T=CreatBinTree ); preorder(t; 返回0; }voidpreorder(bitreet ) if ) t ) printf )、T-data ); preorder(t-lchild ); preorder(t-rchild ); }}BiTree CreatBinTree () ) { char ch; BiTree T; scanf('%c ',ch ); if(ch=='# ' ) /如果当前字符为#,则指示当前节点为空,返回空值; t=(bitree* ) malloc (sizeof ) bitree ); T-data=ch; T-lchild=CreatBinTree (; 调用//函数以创建左子T-rchild=CreatBinTree (; 调用//函数创建右边的子级return T; () ) ) ) )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。