#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<sstream>
#include<istream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn = 50;
int pre[maxn], ino[maxn];
int lch[maxn], rch[maxn];
int n;
bool read(int* a) {
n = 0;
string line;
**if (!(cin >> line))return false;**
stringstream ss(line);
char x = 0;
while (ss >> x)a[n++] = (int)x-64;
while (n > 0)return true;/*检测末尾*/
}
int build(int L1, int R1, int L2, int R2) {
if (L2 > R2)return 0;
int root = pre[L1];
int p=L2;
while (ino[p] != root)p++;/*cnt统计左子树的个数,此处少一*/
int cnt = p - L2;
lch[root] = build(L1 +1, L1 + cnt, L2, p - 1);/*范围按各个遍历的顺序来决定*/
rch[root] = build(L1 + cnt+1, R1, p + 1, R2);
return root;
}
void dfs(int root) {
if (lch[root])dfs(lch[root]);
if (rch[root])dfs(rch[root]);
printf("%c", root + 64);
}
int main() {
while (read(pre)) {
read(ino);
build(0, n - 1, 0, n - 1);
dfs(pre[0]);
printf("\n");
}
return 0;
}
如上有两个星号包围的语句,如果我不加以if进行判定的话,本来ac的代码会runtime error,这是怎么一个情况?