前中后序遍历二叉树

时间:2022-05-04 04:44:53
【文件属性】:
文件名称:前中后序遍历二叉树
文件大小:1KB
文件格式:CPP
更新时间:2022-05-04 04:44:53
C/C++ 简单的前、中、后序遍历二叉树 部分代码:#include #include int Pos=0; typedef struct node { char data; struct node * lchild; struct node * rchild; }BTNode; BTNode* CreateTreePre(char str[]) { char tmp; BTNode *newnode=NULL; tmp = str[Pos++]; if( tmp!= '#') { newnode = (BTNode *)malloc(sizeof(BTNode)); newnode ->data = tmp; newnode ->lchild = CreateTreePre (str); newnode ->rchild = CreateTreePre (str); } return newnode; } void PreOrder(BTNode *b) //先序 { if (b!=NULL) { printf("%c",b->data); PreOrder(b->lchild); PreOrder(b->rchild); } }

网友评论