#include <iostream>
#include <cstring>
#include <string>
#include <Stdlib.h>
using namespace std;
struct person//个人信息
{
int n;
string name;
char sex;
int birthday;
string spouse;
string introdution;
};
typedef struct tree//
{
public:
person people;
tree* brother;
tree* children;
tree* parent;
void createFamily(treep );
int sunday(string src,string des);
void searchbything(treep head);
treep addChild(treep ancestor,treep parent);
treep addbrother(treep newchild,treep parent);
void print(treep head);
void printall(treep head);
void printChild(treep child);
void printbrother(treep parent);
void print_one_member(treep head );
void addmenber(treep member);
treep FindNode(treep Node,string name);
void change_information(treep head);
void deletemmember(treep head);
treep Findintrodution(treep head,string tt);
int isexit(string b,char a);
void printintrodution(treep head,string str);
/
void printintrodution(treep head,string str)//按事迹查找,将关键字传入和节点传入,匹配字符串
{
treep p=NULL;
if((p=Findintrodution(head,str))!=NULL)print(p);//找到,即输出该人的简介
if(p->brother!=NULL)printintrodution(p->brother,str);//寻找兄弟节点
if(p->children!=NULL)printintrodution(p->children,str);//寻找孩子节点
}
/
int isexit(string b,char a)//判断字符串是否匹配,匹配返回字符串的位置,否则返回-1
{
int lenb=b.length();
int i=lenb-1;
while(i>=0)
{
if(b[i]==a)return lenb-i;//返回字符串移动的长度
i--;
}
return -1;
}
/
treep Findintrodution(treep Node,string tt)//
{
treep p=NULL;
if(Node!=NULL)
{
if(sunday(Node->people.introdution,tt)!=-1)
p=Node;
else
{
p=Findintrodution(Node->children,tt);
if(p!=NULL)return p;
else
p=Findintrodution(Node->brother,tt);
}
}
return p;
{
int lena=a.length();
int lenb=b.length();
int i=0;
int start=0;
int pos;
if(lenb>lena||lenb==0||lena==0)return -1;
while(start+lenb<=lena)
{
while(a[i+start]==b[i]&&i<lenb)
{
i++;
}
if(i==lenb){return start;break;}
else
{
if(pos=isexit(b,a[lenb+start])!=-1)start+=pos;
else start+=(lenb+1);
}
}
return -1;
}
/
void deletemmember(treep head)
{
system("cls");
cout<<"请输入要删除的成员的名称"<<endl;
string name;
cin>>name;
treep p=FindNode(head,name);
if(p==NULL)cout<<"未找到此人!"<<endl;
else
{
p->people.name+="(已删除)";
//for(int i=0;i<200;i++)
p->people.introdution=" ";
p->people.birthday=00000000;
p->people.sex=' ';
p->people.spouse=" ";
cout<<"删除成功!"<<endl;
}
}
/
void change_information(treep head)
{
system("cls");
int num=1;
cout<<"请输入要改变的成员的名称"<<endl;
string name;
cin>>name;
treep p=FindNode(head,name);
if(p==NULL){cout<<"未找到此人!"<<endl;system("cls");}
else
{
while(num==1)
{
cout<<"1.修改该成员的名字"<<endl;
cout<<"2.修改该成员的配偶"<<endl;
cout<<"3.修改该成员的生辰"<<endl;
cout<<"4.修改该成员的性别"<<endl;
int n;
cin>>n;
switch(n)
{
case 1:
{
cout<<"请输入新的名称"<<endl;
string newname;
cin>>newname;
p->people.name=newname;
break;
}
case 2:
{
cout<<"请输入配偶的名称"<<endl;
string spouse;
cin>>spouse;
p->people.spouse=spouse;
break;
}
case 3:
{
cout<<"请输入生日"<<endl;
int birthday;
cin>>birthday;
p->people.birthday=birthday;
break;
}
case 4:
{
cout<<"请输入性别(m为男,g为女)"<<endl;
char sex;
cin>>sex;
p->people.sex=sex;
break;
}
}
cout<<"修改成功,继续请按1,退出请按0"<<endl;
cin>>num;
}
system("cls");
}
}
/
treep FindNode(treep Node,string name)
{
treep p=NULL;
if(Node!=NULL)
{
if(Node->people.name==name)p=Node;
else
{
p=FindNode(Node->children,name);
if(p!=NULL)return p;
else
p=FindNode(Node->brother,name);
}
}
return p;
}
/
void addmember(treep head)
{
treep member=new tree;
treep p=new tree;
cout<<"请输入该成员的父亲名称"<<endl;
string name;
cin>>name;
p=FindNode(head,name);
if(p==NULL){cout<<"未找到此人!"<<endl;system("cls");}
else
{
cout<<"请输入该成员的名称"<<endl;
string newname;
cin>>newname;
member->people.name=newname;
cout<<"请输入"<<member->people.name<<"的性别(m为男,g为女)"<<endl;
char sex;
cin>>sex;
member->people.sex=sex;
cout<<"请输入"<<member->people.name<<"的生日"<<endl;
int birthday;
cin>>birthday;
member->people.birthday=birthday;
cout<<member->people.name<<"是否已婚(yes or no)"<<endl;
string pan;
cin>>pan;
if(pan=="yes")
{
cout<<"请输入配偶的名称"<<endl;
string spouse_name;
cin>>spouse_name;
member->people.spouse=spouse_name;
}
cout<<"请输入"<<member->people.name<<"的简介"<<endl;
string introdution;
cin>>introdution;
int length=introdution.length();
member->people.introdution=introdution;
member->people.n=p->people.n+1;
member->children=NULL;
member->brother=NULL;
member->parent=p;
if(p->children==NULL)p->children=member;
else
{
p=p->children;
if(p->brother==NULL)p->brother=member;
else
{
while(p->brother!=NULL)
{p=p->brother;}
p->brother=member;
}
}
}
cout<<"添加成功!"<<endl;
}
/
void mainmenu(treep head)
{
cout<<" 族谱程序 "<<endl;
cout<<" 1.创建族谱 "<<endl;
cout<<" 2.删除家族成员 "<<endl;
cout<<" 3.输出全部家族成员 "<<endl;
cout<<" 4.修改家族成员信息 "<<endl;
cout<<" 5.增加家族成员 "<<endl;
cout<<" 6.输出某一个家族成员的信息 "<<endl;
cout<<" 7.按照事迹查询家族成员 "<<endl;
cout<<" 8.退出系统 "<<endl;
cout<<" "<<endl;
int n;
cin>>n;
switch(n)
{
case 1:system("cls");createFamily(head);break;
case 2:
{
system("cls");
deletemmember(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 3:
{
system("cls");
printall(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 4:
{
system("cls");
change_information(head);
break;
}
case 5:
{
system("cls");
addmember(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 6:
{
system("cls");
print_one_member(head);
//system("cls");
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 7:
{
system("cls");
searchbything(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 8:exit(0);
}
}
/
treep init()
{
treep ancestor;
ancestor=new tree;
ancestor->people.n=1;
cout<<" 请输入祖先的信息"<<endl<<endl;
cout<<"请输入祖先的名字"<<endl;
cin>>ancestor->people.name;
cout<<"请输入祖先的生辰(格式为19940517)"<<endl;
cin>>ancestor->people.birthday;
cout<<"请输入祖先的性别(m为男,g为女)"<<endl;
cin>>ancestor->people.sex;
cout<<"请输入祖先的配偶"<<endl;
cin>>ancestor->people.spouse;
cout<<"请输入祖先的简介(不得超过200字)"<<endl;
cin>>ancestor->people.introdution;
ancestor->brother=NULL;
ancestor->children=NULL;
ancestor->parent=NULL;
system("cls");
return ancestor;
}
void createFamily(treep ancestor)//创建族谱
{
cout<<"给"<<ancestor->people.name<<"添加后代"<<endl;
ancestor->children=addChild(ancestor->children,ancestor);//调用添加子代的函数
}
/
brother=new tree;
brother->parent=newchild->parent;//将传入的的
brother->people.n=newchild->people.n;
string name;
string pan1;
string pan2;
string pan3;
cout<<"请输入"<<newchild->people.name<<"弟弟或妹妹的名字"<<endl;
cin>>brother->people.name;
cout<<"请输入"<<brother->people.name<<"的出生年月"<<endl;
cin>>brother->people.birthday;
cout<<"请输入"<<brother->people.name<<"的性别(m为男,g为女)"<<endl;
cin>>brother->people.sex;
cout<<"请输入"<<brother->people.name<<"的简介"<<endl;
cin>>brother->people.introdution;
cout<<brother->people.name<<"是否有配偶(yes or no)"<<endl;
cin>>pan1;
if(pan1=="yes")
{
cin>>brother->people.spouse;
cout<<brother->people.name<<"是否有子女(yes or no)"<<endl;
cin>>pan2;
if(pan2=="yes")brother->children=addChild(brother->children,brother);
else if(pan2=="no")brother->children=NULL;
}
if(pan1=="no")
{
brother->people.spouse="无";
brother->children=NULL;
}
cout<<"是否继续添加弟弟或妹妹(yes or no)"<<endl;
cin>>pan3;
if(pan3=="yes")brother->brother=addbrother(brother->brother,brother);
else
if(pan3=="no")brother->brother=NULL;
return brother;
}
//
treep addChild(treep newchild,treep parent)
{
string pan;
string pan1;
string pan2;
string spouse_name;
newchild =new tree;
newchild->parent=parent;
newchild->people.n=parent->people.n+1;
cout<<"请输入"<<parent->people.name<<"的孩子的名字"<<endl;
cin>>newchild->people.name;
cout<<"请输入"<<newchild->people.name<<"的出生年月"<<endl;
cin>>newchild->people.birthday;
cout<<"请输入"<<newchild->people.name<<"的性别(m为男,g为女)"<<endl;
cin>>newchild->people.sex;
cout<<"请输入"<<newchild->people.name<<"的简介"<<endl;
cin>>newchild->people.introdution;
cout<<newchild->people.name<<"是否有配偶(yes or no)"<<endl;
cin>>pan;
if(pan=="yes")
{
cout<<"请输入配偶名称"<<endl;
cin>>spouse_name;
cout<<newchild->people.name<<"是否有孩子(yes or no)"<<endl;
cin>>pan1;
if(pan1=="yes")
{
system("cls");
createFamily(newchild);
}
else newchild->children=NULL;
}
if(pan=="no")
{
newchild->people.spouse="无";
newchild->children=NULL;
}
cout<<newchild->people.name<<"是否有兄弟(yes or no)"<<endl;
cin>>pan2;
if(pan2=="yes")
{
newchild->brother=addbrother(newchild->brother,newchild);
}
if(pan2=="no")newchild->brother=NULL;
system("cls");
return newchild;
}
void print_one_member(treep head)
{
system("cls");
cout<<"请输入该人的名字"<<endl;
string name;
cin>>name;
treep p;
p=FindNode(head,name);
if(p==NULL)cout<<"未找到此人!"<<endl;
else
print(p);
}
void printChild(treep child)
{
cout<<child->people.name<<" ";
if(child->brother!=NULL)
printChild(child->brother);
cout<<endl;
}
/
void printbrother(treep parent)
{
cout<<parent->children->people.name<<" ";
printChild(parent->children);
}
/
void print(treep head)
{
cout<<"——————————————————"<<endl;
cout<<"姓名: "<<head->people.name<<endl;
cout<<"辈分: 第"<<head->people.n<<"代"<<endl;
cout<<"性别: ";
if(head->people.sex=='m')cout<<"男"<<endl;
if(head->people.sex=='g')cout<<"女"<<endl;
cout<<endl;
cout<<"生日: "<<head->people.birthday<<endl;
if(head!=NULL&&head->parent!=NULL)
cout<<"父母: "<<head->parent->people.name<<' '<<head->parent->people.spouse <<endl;
else
cout <<"父母: "<<endl;
if(head->people.spouse=="无")
cout<<"配偶: 未婚"<<endl;
if(head->people.spouse!="无")
cout<<"配偶: "<<head->people.spouse<<endl;
if(head->children!=NULL)
{
cout<<"孩子: ";
printChild(head->children);
}
if(head->children==NULL)
cout<<"孩子: 无孩子"<<endl;
if(head->brother==NULL)
cout<<"兄弟: "<<"无兄弟"<<endl;
if(head->brother!=NULL)
{
cout<<"兄弟: "<<head->brother->people.name<<endl;
printbrother(head->parent);
}
cout<<"简介:"<<head->people.introdution<<endl;
cout<<"——————————————————"<<endl;
}
/
void printall(treep head)
{
if(head!=NULL)print(head);
if(head->brother!=NULL)printall(head->brother);
if(head->children!=NULL)printall(head->children);
}
/
int main()
{
head=init();
while(1)
{
mainmenu(head);
}
return 0;
#include <cstring>
#include <string>
#include <Stdlib.h>
using namespace std;
struct person//个人信息
{
int n;
string name;
char sex;
int birthday;
string spouse;
string introdution;
};
typedef struct tree//
{
public:
person people;
tree* brother;
tree* children;
tree* parent;
}tree,* treep;
void createFamily(treep );
int sunday(string src,string des);
void searchbything(treep head);
treep addChild(treep ancestor,treep parent);
treep addbrother(treep newchild,treep parent);
void print(treep head);
void printall(treep head);
void printChild(treep child);
void printbrother(treep parent);
void print_one_member(treep head );
void addmenber(treep member);
treep FindNode(treep Node,string name);
void change_information(treep head);
void deletemmember(treep head);
treep Findintrodution(treep head,string tt);
int isexit(string b,char a);
void printintrodution(treep head,string str);
/
void printintrodution(treep head,string str)//按事迹查找,将关键字传入和节点传入,匹配字符串
{
treep p=NULL;
if((p=Findintrodution(head,str))!=NULL)print(p);//找到,即输出该人的简介
if(p->brother!=NULL)printintrodution(p->brother,str);//寻找兄弟节点
if(p->children!=NULL)printintrodution(p->children,str);//寻找孩子节点
}
/
int isexit(string b,char a)//判断字符串是否匹配,匹配返回字符串的位置,否则返回-1
{
int lenb=b.length();
int i=lenb-1;
while(i>=0)
{
if(b[i]==a)return lenb-i;//返回字符串移动的长度
i--;
}
return -1;
}
/
treep Findintrodution(treep Node,string tt)//
{
treep p=NULL;
if(Node!=NULL)
{
if(sunday(Node->people.introdution,tt)!=-1)
p=Node;
else
{
p=Findintrodution(Node->children,tt);
if(p!=NULL)return p;
else
p=Findintrodution(Node->brother,tt);
}
}
return p;
}
/
void searchbything(treep head)
{
cout<<" 事迹查询 "<<endl;
cout<<"请输入关键字"<<endl;
string str;
cin>>str;
cout<<"查找结果。。。。。"<<endl;
printintrodution(head,str);
}
/
{
int lena=a.length();
int lenb=b.length();
int i=0;
int start=0;
int pos;
if(lenb>lena||lenb==0||lena==0)return -1;
while(start+lenb<=lena)
{
while(a[i+start]==b[i]&&i<lenb)
{
i++;
}
if(i==lenb){return start;break;}
else
{
if(pos=isexit(b,a[lenb+start])!=-1)start+=pos;
else start+=(lenb+1);
}
}
return -1;
}
/
void deletemmember(treep head)
{
system("cls");
cout<<"请输入要删除的成员的名称"<<endl;
string name;
cin>>name;
treep p=FindNode(head,name);
if(p==NULL)cout<<"未找到此人!"<<endl;
else
{
p->people.name+="(已删除)";
//for(int i=0;i<200;i++)
p->people.introdution=" ";
p->people.birthday=00000000;
p->people.sex=' ';
p->people.spouse=" ";
cout<<"删除成功!"<<endl;
}
}
/
void change_information(treep head)
{
system("cls");
int num=1;
cout<<"请输入要改变的成员的名称"<<endl;
string name;
cin>>name;
treep p=FindNode(head,name);
if(p==NULL){cout<<"未找到此人!"<<endl;system("cls");}
else
{
while(num==1)
{
cout<<"1.修改该成员的名字"<<endl;
cout<<"2.修改该成员的配偶"<<endl;
cout<<"3.修改该成员的生辰"<<endl;
cout<<"4.修改该成员的性别"<<endl;
int n;
cin>>n;
switch(n)
{
case 1:
{
cout<<"请输入新的名称"<<endl;
string newname;
cin>>newname;
p->people.name=newname;
break;
}
case 2:
{
cout<<"请输入配偶的名称"<<endl;
string spouse;
cin>>spouse;
p->people.spouse=spouse;
break;
}
case 3:
{
cout<<"请输入生日"<<endl;
int birthday;
cin>>birthday;
p->people.birthday=birthday;
break;
}
case 4:
{
cout<<"请输入性别(m为男,g为女)"<<endl;
char sex;
cin>>sex;
p->people.sex=sex;
break;
}
}
cout<<"修改成功,继续请按1,退出请按0"<<endl;
cin>>num;
}
system("cls");
}
}
/
treep FindNode(treep Node,string name)
{
treep p=NULL;
if(Node!=NULL)
{
if(Node->people.name==name)p=Node;
else
{
p=FindNode(Node->children,name);
if(p!=NULL)return p;
else
p=FindNode(Node->brother,name);
}
}
return p;
}
/
void addmember(treep head)
{
treep member=new tree;
treep p=new tree;
cout<<"请输入该成员的父亲名称"<<endl;
string name;
cin>>name;
p=FindNode(head,name);
if(p==NULL){cout<<"未找到此人!"<<endl;system("cls");}
else
{
cout<<"请输入该成员的名称"<<endl;
string newname;
cin>>newname;
member->people.name=newname;
cout<<"请输入"<<member->people.name<<"的性别(m为男,g为女)"<<endl;
char sex;
cin>>sex;
member->people.sex=sex;
cout<<"请输入"<<member->people.name<<"的生日"<<endl;
int birthday;
cin>>birthday;
member->people.birthday=birthday;
cout<<member->people.name<<"是否已婚(yes or no)"<<endl;
string pan;
cin>>pan;
if(pan=="yes")
{
cout<<"请输入配偶的名称"<<endl;
string spouse_name;
cin>>spouse_name;
member->people.spouse=spouse_name;
}
cout<<"请输入"<<member->people.name<<"的简介"<<endl;
string introdution;
cin>>introdution;
int length=introdution.length();
member->people.introdution=introdution;
member->people.n=p->people.n+1;
member->children=NULL;
member->brother=NULL;
member->parent=p;
if(p->children==NULL)p->children=member;
else
{
p=p->children;
if(p->brother==NULL)p->brother=member;
else
{
while(p->brother!=NULL)
{p=p->brother;}
p->brother=member;
}
}
}
cout<<"添加成功!"<<endl;
}
/
void mainmenu(treep head)
{
cout<<" 族谱程序 "<<endl;
cout<<" 1.创建族谱 "<<endl;
cout<<" 2.删除家族成员 "<<endl;
cout<<" 3.输出全部家族成员 "<<endl;
cout<<" 4.修改家族成员信息 "<<endl;
cout<<" 5.增加家族成员 "<<endl;
cout<<" 6.输出某一个家族成员的信息 "<<endl;
cout<<" 7.按照事迹查询家族成员 "<<endl;
cout<<" 8.退出系统 "<<endl;
cout<<" "<<endl;
int n;
cin>>n;
switch(n)
{
case 1:system("cls");createFamily(head);break;
case 2:
{
system("cls");
deletemmember(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 3:
{
system("cls");
printall(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 4:
{
system("cls");
change_information(head);
break;
}
case 5:
{
system("cls");
addmember(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 6:
{
system("cls");
print_one_member(head);
//system("cls");
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 7:
{
system("cls");
searchbything(head);
int n;
cout<<"输入0退出"<<endl;
cin>>n;
if(n==0)system("cls");
break;
}
case 8:exit(0);
}
}
/
treep init()
{
treep ancestor;
ancestor=new tree;
ancestor->people.n=1;
cout<<" 请输入祖先的信息"<<endl<<endl;
cout<<"请输入祖先的名字"<<endl;
cin>>ancestor->people.name;
cout<<"请输入祖先的生辰(格式为19940517)"<<endl;
cin>>ancestor->people.birthday;
cout<<"请输入祖先的性别(m为男,g为女)"<<endl;
cin>>ancestor->people.sex;
cout<<"请输入祖先的配偶"<<endl;
cin>>ancestor->people.spouse;
cout<<"请输入祖先的简介(不得超过200字)"<<endl;
cin>>ancestor->people.introdution;
ancestor->brother=NULL;
ancestor->children=NULL;
ancestor->parent=NULL;
system("cls");
return ancestor;
}
void createFamily(treep ancestor)//创建族谱
{
cout<<"给"<<ancestor->people.name<<"添加后代"<<endl;
ancestor->children=addChild(ancestor->children,ancestor);//调用添加子代的函数
}
/
treep addbrother(treep brother,treep newchild)
//添加兄弟函数
{brother=new tree;
brother->parent=newchild->parent;//将传入的的
brother->people.n=newchild->people.n;
string name;
string pan1;
string pan2;
string pan3;
cout<<"请输入"<<newchild->people.name<<"弟弟或妹妹的名字"<<endl;
cin>>brother->people.name;
cout<<"请输入"<<brother->people.name<<"的出生年月"<<endl;
cin>>brother->people.birthday;
cout<<"请输入"<<brother->people.name<<"的性别(m为男,g为女)"<<endl;
cin>>brother->people.sex;
cout<<"请输入"<<brother->people.name<<"的简介"<<endl;
cin>>brother->people.introdution;
cout<<brother->people.name<<"是否有配偶(yes or no)"<<endl;
cin>>pan1;
if(pan1=="yes")
{
cin>>brother->people.spouse;
cout<<brother->people.name<<"是否有子女(yes or no)"<<endl;
cin>>pan2;
if(pan2=="yes")brother->children=addChild(brother->children,brother);
else if(pan2=="no")brother->children=NULL;
}
if(pan1=="no")
{
brother->people.spouse="无";
brother->children=NULL;
}
cout<<"是否继续添加弟弟或妹妹(yes or no)"<<endl;
cin>>pan3;
if(pan3=="yes")brother->brother=addbrother(brother->brother,brother);
else
if(pan3=="no")brother->brother=NULL;
return brother;
}
//
treep addChild(treep newchild,treep parent)
{
string pan;
string pan1;
string pan2;
string spouse_name;
newchild =new tree;
newchild->parent=parent;
newchild->people.n=parent->people.n+1;
cout<<"请输入"<<parent->people.name<<"的孩子的名字"<<endl;
cin>>newchild->people.name;
cout<<"请输入"<<newchild->people.name<<"的出生年月"<<endl;
cin>>newchild->people.birthday;
cout<<"请输入"<<newchild->people.name<<"的性别(m为男,g为女)"<<endl;
cin>>newchild->people.sex;
cout<<"请输入"<<newchild->people.name<<"的简介"<<endl;
cin>>newchild->people.introdution;
cout<<newchild->people.name<<"是否有配偶(yes or no)"<<endl;
cin>>pan;
if(pan=="yes")
{
cout<<"请输入配偶名称"<<endl;
cin>>spouse_name;
cout<<newchild->people.name<<"是否有孩子(yes or no)"<<endl;
cin>>pan1;
if(pan1=="yes")
{
system("cls");
createFamily(newchild);
}
else newchild->children=NULL;
}
if(pan=="no")
{
newchild->people.spouse="无";
newchild->children=NULL;
}
cout<<newchild->people.name<<"是否有兄弟(yes or no)"<<endl;
cin>>pan2;
if(pan2=="yes")
{
newchild->brother=addbrother(newchild->brother,newchild);
}
if(pan2=="no")newchild->brother=NULL;
system("cls");
return newchild;
}
void print_one_member(treep head)
{
system("cls");
cout<<"请输入该人的名字"<<endl;
string name;
cin>>name;
treep p;
p=FindNode(head,name);
if(p==NULL)cout<<"未找到此人!"<<endl;
else
print(p);
}
void printChild(treep child)
{
cout<<child->people.name<<" ";
if(child->brother!=NULL)
printChild(child->brother);
cout<<endl;
}
/
void printbrother(treep parent)
{
cout<<parent->children->people.name<<" ";
printChild(parent->children);
}
/
void print(treep head)
{
cout<<"——————————————————"<<endl;
cout<<"姓名: "<<head->people.name<<endl;
cout<<"辈分: 第"<<head->people.n<<"代"<<endl;
cout<<"性别: ";
if(head->people.sex=='m')cout<<"男"<<endl;
if(head->people.sex=='g')cout<<"女"<<endl;
cout<<endl;
cout<<"生日: "<<head->people.birthday<<endl;
if(head!=NULL&&head->parent!=NULL)
cout<<"父母: "<<head->parent->people.name<<' '<<head->parent->people.spouse <<endl;
else
cout <<"父母: "<<endl;
if(head->people.spouse=="无")
cout<<"配偶: 未婚"<<endl;
if(head->people.spouse!="无")
cout<<"配偶: "<<head->people.spouse<<endl;
if(head->children!=NULL)
{
cout<<"孩子: ";
printChild(head->children);
}
if(head->children==NULL)
cout<<"孩子: 无孩子"<<endl;
if(head->brother==NULL)
cout<<"兄弟: "<<"无兄弟"<<endl;
if(head->brother!=NULL)
{
cout<<"兄弟: "<<head->brother->people.name<<endl;
printbrother(head->parent);
}
cout<<"简介:"<<head->people.introdution<<endl;
cout<<"——————————————————"<<endl;
}
/
void printall(treep head)
{
if(head!=NULL)print(head);
if(head->brother!=NULL)printall(head->brother);
if(head->children!=NULL)printall(head->children);
}
/
int main()
{
head=init();
while(1)
{
mainmenu(head);
}
return 0;
}
(1).首先初始化族谱,即建立一个头结点
(2).选择创建族谱,即用二叉树建立链表,添加子节点。
(3).采用先序遍历,各种操作基本都是在遍历到某一节点再进行操作
(4).按事迹查找使用关键字搜索,即遍历各节点的简介,将关键字与简介匹配。字符串匹配采用Sunday算法,简洁明了。
(5).程序有BUG,在输出兄弟时会重复输出,未来得及优化