#include<bits/stdc++.h>
using namespace std;
struct TreeNode{
struct TreeNode * lchild, *rchild;
int val;
TreeNode(int x): val(x), lchild(NULL), rchild(NULL){}
};
void create(TreeNode* &root){
char x;
cin >> x;
if(x == '#')
root = NULL;
else{
root = new TreeNode(x - '0');
create(root->lchild);
create(root->rchild);
}
}
void pre(TreeNode* root){
if(root){
cout << root->val << " ";
pre(root->lchild);
pre(root->rchild);
}
}
int main(){
TreeNode * root;
create(root);
cout << "create finish!" << endl;
pre(root);
return 0;
}
来源:CSDN
作者:qq_31672701
链接:https://blog.csdn.net/qq_31672701/article/details/104791965