#include <stdio.h>
#include <stdlib.h>
#include<math.h>
#include<string.h>
#define MAXSIZE 100
typedef struct Infomation{
char name[20];
char birth[20];
int wedding;
char add[20];
int health;
char death_date[20];
}Info;
typedef struct node
{
Info person;
struct node *lchild,*rchild;
}Bnode,*tree;
typedef struct mode
{
tree queue[MAXSIZE];
int front,rear;
}Queue;
void init(Queue Q)
{
Q.front=Q.rear=0;
}
void push(Queue *Q,tree e)//入队
{
Q->rear=(Q->rear+1)%MAXSIZE;
Q->queue[Q->front]=e;
}
void pop(Queue *Q,tree *e)//出队
{
Q->front=(Q->front+1)%MAXSIZE;
*e=Q->queue[Q->front];
}
int empty(Queue Q)//判队空
{
if(Q.front==Q.rear)
return 1;
else return 0;
}
int full(Queue Q)//判队满
{
if((Q.rear+1)%MAXSIZE==Q.front)
return 1;
else return 0;
}
void newleft(tree p,Info L)
{
tree q;
q=(tree)malloc(sizeof(Bnode));
q->person=L;
q->lchild=q->rchild=NULL;
p->lchild=q;
}
void newright(tree p,Info L)
{
tree q;
q=(tree)malloc(sizeof(Bnode));
q->person=L;
q->lchild=q->rchild=NULL;
p->rchild=q;
}
tree creat()
{
FILE *fp;
int i;
Info human[11];
if ((fp=fopen("family.txt","r+"))==NULL)
{
printf("不能打开家谱文件\n");
}
for(i=0;i<11;i++)
{
fscanf(fp,"%s %s %d %s %d",human[i].name,human[i].birth,&human[i].wedding,human[i].add,&human[i].health);
fgets(human[i].death_date,20,fp);
printf("%-7s%-15s%-7d%-12s%-10d%-20s\n",human[i].name,human[i].birth,human[i].wedding,human[i].add,human[i].health,human[i].death_date);
}
fclose(fp);
tree bt;
bt=(tree)malloc(sizeof(Bnode));
bt->person=human[0];
bt->lchild=bt->rchild=NULL;
newleft(bt,human[1]);
newright(bt,human[2]);
newleft(bt->lchild,human[3]);
newright(bt->lchild,human[4]);
newleft(bt->rchild,human[5]);
newright(bt->rchild,human[6]);
newleft(bt->lchild->lchild,human[7]);
newright(bt->lchild->lchild,human[8]);
newleft(bt->rchild->rchild,human[9]);
newright(bt->rchild->rchild->lchild,human[10]);
return bt;
}
void output(tree p)
{
printf("%-7s%-15s%-7d%-12s%-10d%-20s\n",p->person.name,p->person.birth,p->person.wedding,p->person.add,p->person
C语言课程设计——家谱
最新推荐文章于 2023-07-25 22:51:38 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)