二叉树的先序建树后序输出
生活随笔
收集整理的這篇文章主要介紹了
二叉树的先序建树后序输出
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼~:
#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;}總結
以上是生活随笔為你收集整理的二叉树的先序建树后序输出的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 指针+strstr
- 下一篇: 完全二叉树每层元素的查找