怎么让管虎**结构试验(用C语言)建立一棵二叉树,并用递归或者非递归的算法分别用先序。中序和后序遍历、谢谢第1个回答:jjcflrq2017-12-15关注#defi

第1个回答:

jjcflrq2017-12-15关注#defineLENsizeof(structtree)#define**LL0#include<stdio.h>#include<malloc.h>structtree{chardata;structtree*lchild,*rchild;};//创建二叉树structtree*creat(){charc;structtree*t;c=getchar();if(c=='')t=**LL;else{t=(structtree*)malloc(LEN);t->data=c;t->lchild=creat();t->rchild=creat();}returnt;}//前序遍历voidPreprint(structtree*t){if(t!=**LL){printf("%c->",t->data);Preprint(t->lchild);Preprint(t->rchild);}}//中序遍历voidInprint(structtree*t){if(t!=**LL){Inprint(t->lchild);printf("%c->",t->data);Inprint(t->rchild);}}//后序遍历voidPostprint(structtree*t){if(t!=**LL){Postprint(t->lchild);Postprint(t->rchild);printf("%c->",t->data);}}main(){structtree*t;printf("Pleaseinputtreeinorder:\n");t=creat();printf("TheresultofPreordertr**ersalis\n");Preprint(t);printf("^\nTheresultofInordertr**ersalis\n");Inprint(t);printf("^\nTheresultofPostordertr**ersalis\n");Postprint(t);printf("^\n");getch();}