#include<cstdio> #include<string> using namespace std; struct TreeNode { char data; TreeNode* LChild; TreeNode* RChild; }; TreeNode* RecursiveBuildTree(int& i, string str) { //返回本棵子树根节点地址; char c = str[i]; ++i; if (c == '#') { return NULL; } else { TreeNode* pa = new TreeNode; pa->data = c; pa->LChild = RecursiveBuildTree(i, str); pa->RChild = RecursiveBuildTree(i, str); return pa ; } } void MidOrder(TreeNode* root) { if (root == NULL) { return; } MidOrder(root->LChild); printf("%c ", root->data); MidOrder(root->RChild); } int main() { char arr[100]; while (scanf("%s", arr) != EOF) { string str = arr; int i = 0 ; TreeNode* root = RecursiveBuildTree(i, str); MidOrder(root); printf("\n"); } }