帮忙找找bug吧!我明天就要交作业了QWQ球球了
#include <iostream>
#include <string>
using namespace std;
string k;
struct tree {
string v;
tree *lt;
tree *rt;
};
tree a[101];
void bl(tree *t)
{
if (t != 0)
{
cout << t->v << " ";
bl(t->lt);
bl(t->rt);
}
}
void find_father(tree *t)
{
if (t != 0)
{
if (t->lt->v == k || t->rt->v == k)
{
cout << t->v << "\n";
}
else
{
find_father(t->lt);
find_father(t->rt);
}
}
}
void find_son(tree *t)
{
if (t != 0)
{
if (t->v == k)
{
bl(t);
}
else
{
find_son(t->lt);
find_son(t->rt);
}
}
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i].v;
}
for (int i = 1; i <= n / 2; i++)
{
a[i].lt = &a[2 * i];
a[i].rt = &a[2 * 1 + 1];
}
if (n % 2 == 0)
{
a[n / 2].rt = 0;
}
cin >> k;
find_father(&a[1]);
find_son(&a[1]);
return 0;
}