#include<bits/stdc++.h>
using namespace std;
void fun(char bt[],char c)
{
int i=0;
while(bt[i]!='\n')
{
if(bt[i]!=c) i++;
else break;
}
int n=strlen(bt);
if(i==n)
{
cout<<"没有该结点"<<endl;
}
else if(i==0)
{
cout<<"该节点为根,没有双亲"<<endl;
}
else cout<<"该节点的双亲为:"<<bt[(i+1)/2-1]<<endl;
if(bt[2*(i+1)-1]=='#'||2*(i+1)>n)
{
cout<<"该节点没有左孩子"<<endl;
}
else
cout<<"该节点的左孩子为:"<<bt[2*(i+1)-1]<<endl;
if(bt[2*(i+1)]=='#'||2*(i+1)+1>n)
{
cout<<"该节点没有右孩子"<<endl;
}
else
cout<<"该节点的右孩子为:"<<bt[2*(i+1)]<<endl;
return ;
}
int main()
{
char bt[100];
char c;
cout<<"please create a binary tree:";
cin>>bt;
while(1)
{
cout<<"please choose the node you want to search :";
cin>>c;
fun(bt,c);
}
return 0;
}