当前位置:首页 » 编程语言 » 家谱管理程序c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

家谱管理程序c语言

发布时间: 2023-04-11 21:12:50

c语言的家谱图。。想求一个运用结构链表的源程序

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>

#define OK 1
#define ERROR -1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10

typedef int Status;

struct BiNode{
//用结构体定义结点类型。
//数据域信息包含家谱中该对的男、女名字,其双亲名字,以及这对夫妇位于家谱中的辈分
//指针域指向他们的第一个孩子以及其他兄弟
char man[10],woman[10],father[10],mother[10];
int level;
struct BiNode *firstchild,*nextsibling;
};
struct SqStack{
//对栈类型进行定义
BiNode *base;
BiNode *top;
int stacksize;
};

//函数声明
Status InitStack (SqStack &S);
Status Push (SqStack &S,BiNode e);
Status CreateBiTree(BiNode *s);
Status Pop(SqStack &S,BiNode e);
Status EmptyStack(SqStack &S);
Status Preorder(BiNode *T,char name[10],BiNode *p);
//Status CreateParent(BiNode *s);
void findchildren(BiNode *p);
void putoutchildren(BiNode *q,int n);
void findparents(BiNode *p);
void levelhome(BiNode *T);
void leveling(SqStack S1,SqStack S2,int n);
void print(BiNode *p);

//主函数
void main()
{
BiNode *home=NULL,*p=NULL;
char name[10];
printf("请按先序遍历的顺序根据提示输入家谱信息,不存在则输入“#”\n");
CreateBiTree(home);
printf("层次化的家谱信息为\n");
levelhome(home);
printf("请输入要查找的人的名字");
gets(name);
Preorder(home,name,p);
if(!p)printf("家谱中无此人");
else{
printf("辈分:%d\n",p->level);
printf("孩子信息");
findchildren(p);
printf("父母信息:");
findparents(p);
}
}

//函数定义

Status InitStack (SqStack &S){
//初始化函数
S.base=(BiNode*)malloc(STACK_INIT_SIZE * sizeof(BiNode));
if(!S.base) return ERROR;
S.top=S.base;
S.stacksize =STACK_INIT_SIZE;
return OK;
}

Status Push (SqStack &S,BiNode e){
//将e结点推入栈,作为栈顶元素
if(S.top-S.base >=S.stacksize ){
S.base=(BiNode *)realloc(S.base ,(S.stacksize +STACKINCREMENT)*sizeof(BiNode));
if(!S.base ) return ERROR;
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
return OK;
}

Status Pop(SqStack &S,BiNode e){
//取出栈顶元素
if(S.base==S.top) return ERROR;
e=*--S.top;
return OK;
}

Status EmptyStack(SqStack &S){
//若栈空,则返回0
return (S.top == NULL);
}

Status CreateBiTree(BiNode *root){
//创建家谱二叉树
char man1[10],woman1[10],father[10],mother[10];
printf("man:");//男方名字,不存在则输入“#”
gets(man1);
printf("woman:");//女方名字,不存在则输入“#”
gets(man1);
if(strcmp(man1,"#")==0&&strcmp(woman1,"#")==0)//若该结点男女都不存在,则说明该结点为空,即该子树的根结点不存在
{
root=NULL;
}
else{
root=(BiNode *)malloc(sizeof(BiNode));
strcpy(root->man,man1); //将男女的名字赋给该结点的数据域
strcpy(root->woman,woman1);

printf("father:"); //输入该结点的双亲名字
gets(father);
printf("mother:");
gets(mother);

CreateBiTree(root->firstchild); //递归创建该结点的左、右子树
CreateBiTree(root->nextsibling);
root->level=0;//将改结点的层数暂时定义为0
}
return OK;

}

Status Preorder(BiNode *T,char name[10],BiNode *p){
//先序遍历家谱树,查找与name名字相同的结点位置
if(T){
if(strcmp(T->man,name)==0||strcmp(T->woman,name)==0){
p=T;
return OK;
}
else{
if(Preorder(T->firstchild,name,p))return OK;
else return(Preorder(T->nextsibling,name,p));
}
}
else return ERROR;
}

void findchildren(BiNode *p){
//查找所得名字的孩子信息,输出他们的名字,若无孩子,则输出无孩子
int n=1;
BiNode *q;
if(p->firstchild){//该结点的firstchild指针指向的为他的第一个孩子
q=p->firstchild;
putoutchildren(q,n);//输出
}
while(q->nextsibling){
//第一个孩子的nextsibling指针指向的为孩子的兄弟,即第二个孩子
//如此继续,知道结点的右指针为空
q=q->nextsibling;
putoutchildren(q,n);//输出
}
if(n==1)printf("无孩子");
}

void putoutchildren(BiNode *q,int n){
//输出其孩子的结点的信息,并把孩子数加一
printf("第%d个孩子,男方名字%s,女方名字%s\n",n++,q->man,q->woman);
}

void findparents(BiNode *s){
//查询该结点的双亲名字
if(s->father=="#"&&s->mother=="#")
printf("没有父母信息");
else{
if((s->father)!="#")printf("father:%s\n",s->father);
if((s->mother)!="#")printf("mother:%s\n",s->mother);
}
}

void levelhome(BiNode *T){
//按层输出该家谱
SqStack S,N; //定义两个栈并初始化
InitStack(S);
InitStack(N);
BiNode *p;
p=T;
int n=1;
printf("第%d层的信息为:\n");
if(p){
print(p);
p->level=n;//修改p所指向的结点的辈分信息
Push(S,*p);//将该结点推进栈S
}
while(p=p->nextsibling){
//用循环来查找该层的所有信息,只要其nextsibling指向的结点不空,均为同一层
print(p);
p->level=n;
Push(S,*p);
}
while(!EmptyStack(S)||!EmptyStack(N)){
//循环,知道栈S和N都为空,说明按辈分遍历完成
leveling(S,N,n++);
leveling(N,S,n++);
}
printf("\n");
}

void leveling(SqStack S1,SqStack S2,int n){
//将S1栈保存的信息一一取出,查找他孩子的结点,输出其名字,并推入栈S2.
//即S2栈保存的结点是S1的下一辈
BiNode *p,*q;
printf("第%d层的信息为:\n");
while(!EmptyStack(S1)){
Pop(S1,*p);
q=p->firstchild;
if(q){
print(q);
q->level=n;
Push(S2,*q);
while(q=q->nextsibling){
print(q);
q->level=n;
Push(S2,*q);
}
}
}
}

void print(BiNode *p){
//输出该结点处的夫妇名字
printf("%s,%s\\",p->man,p->woman);
}

Ⅱ c语言编写家谱

c语言编写家谱搞定了没 我粗线了

Ⅲ 家谱管理系统设计与实现。编制一个家谱资料管理软件,实现对一个家族所有的资料进行收集整理。

这玩意都到网络来,来错地方了,去专门代编程序设计网站吧,花点钱,会让你很满意的,不舍得花钱的话,就去网络贴吧吧,那里人多

Ⅳ C语言 家谱问题

#include<stdio.h>
#include<string.h>
charw[5][20]={{"child"},{"parent"},{"sibling"},{"descendant"},{"ancestor"}};
intkong(chara[]){
intn=0,i;
for(i=0;a[i]!='';i++){
if(a[i]=='')
n++;
else
break;
}
returnn;
}

charfam[200][20];
intnum[200]={0};

intsearch(chara[],intn){
inti=1;
while(1){
if(!strcmp(a,fam[i]))
returni;
i++;
}
return0;
}

intsearch1(intn,intx){
inti=1;
while(i<x){
if(num[i]==n)
returni;
i++;
}
return0;
}

charname[1000],word[1000],n1[100],n2[100],d[100];
intmain(){
intn,m,i,j,a,b,t,x,k,h;
while(scanf("%d%d",&n,&m)!=EOF){
memset(fam,'',sizeof(fam));
memset(num,'',sizeof(num));
scanf("%s",fam[1]);
getchar();
a=b=2;
t=1;
num[1]=1;
for(i=2;i<=n;i++){
memset(name,'',sizeof(name));
gets(name);
b=kong(name);
if(b>a){
if(fam[search1(t*2+1,i)][0]!='')
t=t*2+1;
else
t=t*2;
}
else{if(b<a){
h=(a-b)/2;
while(h>=1){
t=t/2;
h--;
}
}}
if(fam[search1(t*2,i)][0]!='')
x=t*2+1;
elsex=t*2;
num[i]=x;
for(j=b;name[j]!='';j++)
fam[i][j-b]=name[j];
a=b;
}
for(i=0;i<m;i++){
gets(word);
k=0;h=0;
memset(n1,'',sizeof(n1));
memset(n2,'',sizeof(n2));
memset(d,'',sizeof(d));
for(j=0;word[j]!='';j++){
if(word[j]==''){
k++;
h=0;
continue;
}
if(k==0)
n1[j]=word[j];
if(k==5){
n2[h]=word[j];
h++;
}
if(k==3){
d[h]=word[j];
h++;
}
}
if(!strcmp(d,w[0])){
a=search(n1,n);a=num[a];
b=search(n2,n);b=num[b];
if(a==b*2||a==(b*2+1))
printf("True ");
elseprintf("False ");
continue;
}
if(!strcmp(d,w[1])){
a=search(n1,n);a=num[a];
b=search(n2,n);b=num[b];
if(b==a*2||b==(a*2+1))
printf("True ");
elseprintf("False ");
continue;
}
if(!strcmp(d,w[2])){
a=search(n1,n);a=num[a];
b=search(n2,n);b=num[b];
if((a==b+1&&a==b/2*2+1)||(a==b-1&&b==a/2*2+1))
printf("True ");
elseprintf("False ");
continue;
}
if(!strcmp(d,w[3])){
a=search(n1,n);a=num[a];
b=search(n2,n);b=num[b];
while(a>0){
a=a/2;
if(a==b){
printf("True ");
break;
}
if(a==0)
printf("False ");
}
continue;
}
if(!strcmp(d,w[4])){
a=search(n1,n);a=num[a];
b=search(n2,n);b=num[b];
while(b>0){
b=b/2;
if(a==b){
printf("True ");
break;
}
if(b==0)
printf("False ");
}
continue;
}
}
}
return0;
}

听说回答的够长能够自动采纳

Ⅳ C语言家谱如何分层输出

C语言家谱分层输出代码如下:
*/
#include
#include
#include
#include
#include"map.h"
#defineMAXN100
#defineMAXMEM100
#defineElemtypechar
//
//树
typedefstructBiTNode
{undefined
intmark;//标记
intlevel;
charname[50];//姓名
charbirthday[50];//生日
charaddress[MAXN];//住址
boolmarriage;//婚否(true表示结婚,false表示没结婚)
boollive;//建在(true表示活着,false表示过世)
boolsex;//性别(true表示男,false表示女)
charlivemassage[50];//死亡日期(如果其已经死亡)
Elemtypedata;//
structBiTNode*lc,*rc;
}BiTNode,*BiTree;
//
//树的相关操作
charnametemp[50];//姓名
charbirthdaytemp[50];//生日
charaddresstemp[MAXN];//住址
boolmarriagetemp;//婚否(true表示结婚,false表示没结婚)
boollivetemp;//建在(true表示或者,false表示过世)
boolsextemp;
charlivemassagetemp[MAXN];//死亡日期(如果其已经死亡)
charch;//额外使用
intleveltemp;//人的代数
intNth;//显示第n代人时要用
charsearchdata[50];
charsearchname[50];
intcount;//计数
intchoice;//各种选择
intuse;
BiTreetemp;
structBiTNodeList
{undefined
BiTreedata;
BiTNodeList*next;
};
BiTNodeList*Li
st;
voidCreatBiTree(BiTree&T,FILE*in)//建立双链二叉树
{undefined
fscanf(in,"%c",&ch);
//printf("%c ",ch);
if(ch=='@')
层,意为①重叠起来的东西;重叠起来的东西中的一部分:层次|表层|大气层。②重叠;重复:层峦叠嶂|层出不穷。③量词,用于可以分出层次的事物:三层楼|两层意思|擦掉一层灰。
家谱:又称族谱、宗谱等。是一种以表谱形式,记载一个家族的世系繁衍及重要人物事迹的书。家谱是一种特殊的文献,就其内容而言,是中华文明史中具有平民特色的文献,记载的是同宗共祖血缘集团世系人物和事迹等方面情况的历史图籍。据研究表明,中华古姓来源于图腾崇拜,系氏族徽号或标志。