void displayAllTVShowsOfActor(TVShow* root, string actor) {
string *a = root->actor;
if (root != NULL) {
while (*a != "NULL") {
if (*a == actor)
{
cout << root->name << endl;
}
cout << "here";
a = (a+1);
}
displayAllTVShowsOfActor(root->left, actor);
displayAllTVShowsOfActor(root->right, actor);
}
}
void displayAllTVShowsOfActor(TVShow* root, string actor) {
string *a;
if (root != NULL) {
a = root->actor;
while (*a != "NULL") {
if (*a == actor)
{
cout << root->name << endl;
}
cout << "here";
a = (a+1);
}
displayAllTVShowsOfActor(root->left, actor);
displayAllTVShowsOfActor(root->right, actor);
}
}
第一个导致分段错误,但如果我将第一行移动到 if 语句之后,就像我在第二个中所做的那样,它会起作用。是什么导致了分段错误?