本文主要是介绍二叉树的先序建树后序输出,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码~:
#include <stdio.h>#include <malloc.h>typedef struct Node{char root;struct Node *lchild,*rchild;} BiTNode,*BiTree;BiTree CreateBiTree()//先序建树{BiTree T;char ch;if((ch = getchar() )== '#')return 0;else{T = (BiTNode*)malloc(sizeof(BiTNode));T->root = ch;T->lchild = CreateBiTree();T->rchild = CreateBiTree();return T;}}void postorder(BiTree T)//后序输出{if(T){postorder(T->lchild);postorder(T->rchild);printf("%c",T->root);}}int main(){BiTree T = NULL;T = CreateBiTree();postorder(T);printf("\n");return 0;}
这篇关于二叉树的先序建树后序输出的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!