#include<iostream> #include<cstdio> #include<string> using namespace std; struct TreeNode { char data; TreeNode* leftChild; TreeNode* rightChild; TreeNode(char c):data(c),leftChild(NULL),rightChild(NULL){} }; TreeNode* Build(int& position, string str) { char c = str[position++]; //当前字符 if (c == '#') { return NULL; } TreeNode* root = new TreeNode(c); //创建新结点 root->leftChild = Build(position, str); //创建左子树 root->rightChild = Build(position, str); //创建右子树 return root; } void InOrder(TreeNode* root) { if (root == NULL) { return; } InOrder(root->leftChild); printf("%c ", root->data); InOrder(root->rightChild); return; } int main() { string str; while (cin >> str) { int position = 0; //标记字符串处理位置 TreeNode* root = Build(position, str); InOrder(root); printf("\n"); } system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")