#include <iostream> using namespace std; class node{ public: char data=' '; node* left=nullptr; node* right=nullptr; }; node* buildTree(int& position,string s){ char c = s[position++]; if(c =='#')return nullptr; else{ node*p = new node; p->data = c; p->left = buildTree(position, s); p->right = buildTree(position, s); return p; } } void midOrder(node*p){ if(p==nullptr)return; midOrder(p->left); cout<<p->data<<" "; midOrder(p->right); } int main() { string s;cin>>s; int index=0; node* root = buildTree(index, s); midOrder(root); } // 64 位输出请用 printf("%lld")
照着王道的写的