#include<iostream.h>
typedef int ElemType;
struct BTreeNode{
ElemType date;
BTreeNode* wife,*brother;
BTreeNode* left;
BTreeNode* right;
};
bool find(BTreeNode *BT,ElemType x);
int main()
{BTreeNode *p1,*p2,*p3,*p4,*p5,*p6,*p7;
p1=new BTreeNode;p2=new BTreeNode;p3=new BTreeNode;
p4=new BTreeNode;p5=new BTreeNode;p6=new BTreeNode;
p7=new BTreeNode;
p1->date=1;
p1->left=p2;
p1->right=p3;
p1->brother=NULL;
p1->wife=NULL;
p2->date=2;
p2->left=p5;
p2->right=p6;
p2->brother=p3;
p2->wife=p4;
p3->date=3;
p3->left=NULL;
p3->right=NULL;
p3->brother=p2;
p3->wife=NULL;
p4->date=4;
p4->left=NULL;
p4->right=NULL;
p4->brother=NULL;
p4->wife=NULL;
p5->date=5;
p5->left=p7;
p5->right=NULL;
p5->brother=p6;
p5->wife=NULL;
p6->date=6;
p6->left=NULL;
p6->right=NULL;
p6->brother=p5;
p6->wife=NULL;
p7->date=7;
p7->left=NULL;
p7->right=NULL;
p7->brother=NULL;
p7->wife=NULL;
cout<<"请输入待查的结点数:";
ElemType x;
cin>>x;
find(p1,x);
return 0;
}
bool find(BTreeNode *BT,ElemType x)
{
if(BT->date==x){
if(BT->brother!=NULL)cout<<"兄弟结点是:"<<BT->brother->date<<" ";
if(BT->wife!=NULL)cout<<"妻子结点是:"<<BT->wife->date<<" ";
if(BT->left!=NULL)cout<<"左孩子结点是:"<<BT->left->date<<" ";
if(BT->right!=NULL)cout<<"右孩子结点是:"<<BT->right->date<<" ";
cout<<endl;
return true;
}
else {
if(BT->wife!=NULL) return find(BT->wife,x);
if(BT->brother!=NULL) return find(BT->brother,x);
if(BT->right!=NULL) return find(BT->right,x);
if(BT->left!=NULL) return find(BT->left,x);
}
}