基本二叉树操作
代码:
1 #include <iostream> 2 #include <cstring> 3 4 using namespace std; 5 6 void restore(char *pre, char *in, int len) { 7 if (len == 0) 8 return; 9 10 int left = 0; 11 while (in[left] != pre[0]) 12 left++; 13 restore(pre + 1, in, left); 14 restore(pre + 1 + left, in + 1 + left, len - left - 1); 15 cout << pre[0]; 16 } 17 18 int main() { 19 char pre[32] = {0}; 20 char in[32] = {0}; 21 int len = 0; 22 23 cin >> pre; 24 cin >> in; 25 len = strlen(pre); 26 27 restore(pre, in, len); 28 cout << endl; 29 30 return 0; 31 }