这道题和正常的前序遍历没啥区别,就是改成char而已吧
#include <iostream>
using namespace std;
const int N =300;
char l[N],r[N];
void dfs(char root)
{if(root == '*') return;cout << root;dfs(l[root]);dfs(r[root]);}
int main()
{int n;cin >> n;char root;cin >> root;cin >> l[root] >> r[root];for(int i = 2;i<=n;i++){char t;cin >> t;cin >> l[t] >> r[t];}dfs(root);return 0;
}