题解 | #二叉树遍历#
二叉树遍历
https://www.nowcoder.com/practice/4b91205483694f449f94c179883c1fef
#include <stdio.h> #include <stdlib.h> typedef struct BinTree { struct BinTree*left; struct BinTree*right; char val; }BT; BT* Creater_Tree(char* buff,int* pi)//递归构建二叉树 { if(buff[*pi]=='#') { (*pi)++; return NULL; } BT*Treenode = (BT*)malloc(sizeof(BT)); Treenode->val = buff[(*pi)++]; Treenode->left = Creater_Tree(buff,pi); Treenode->right = Creater_Tree(buff,pi); return Treenode; } void In_Post(BT*root) { if(root==NULL) return; In_Post(root->left); printf("%c ",root->val); In_Post(root->right); } int main() { int i = 0; char str[100]; scanf("%s",str); BT*root = Creater_Tree(str,&i); In_Post(root); return 0; }#刷题#