文档详情

家谱管理系统头文件和源文件.doc

发布:2017-05-21约4.85千字共7页下载文档
文本预览下载声明
#include stdio.h #include string.h #include stdlib.h #include bb.h void main() { BTree *bt; FamilyType fam[MaxSize]; int n,sel1,sel2; ReadFile(fam,n); do { printf(1:文件操作 2:家谱操作 0:退出系统); scanf(%d,sel1); switch(sel1) { case 1: do { printf(1:输入家谱 2:输出家谱 4:清除家谱 0:存盘返回); scanf(%d,sel2); switch(sel2) { case 1: InputFam(fam,n); break; case 2: OutputFile(fam,n); break; case 4: DelAll(fam,n); break; case 0: SaveFile(fam,n); break; } }while(sel2!=0); break; case 2: bt=CreateBTree(f1,fam,n) do { printf(1:括号表示法输出 2:找某人所有儿子 3:找某人所有祖先 0:返回系统主界面:); scanf(%d,sel2); switch(sel2) { case 1: printf( ); PrintBTree(bt); printf(\n); break; case 2: FindSon(bt); break; case 3: printf( ); Ancestor(bt); break; } }while(sel2!=0); break; } }while(sel1!=0); } #include stdio.h #include stdlib.h #include string.h #define MaxWidth 40 #define NAMEWIDTH 10 #define MaxSize 30 typedef struct fnode { char father[NAMEWIDTH]; char wife[NAMEWIDTH]; char son[NAMEWIDTH]; }FamilyType; typedef struct tnode { char name[NAMEWIDTH]; struct tnode *lchild,*rchild; }BTree; BTree *CreateBTree(char *root,FamilyType fam[],int n) { int i=0,j; BTree *bt,*p; bt=(BTree *)malloc(sizeof(BTree)); strcpy(bt-name,root); bt-lchild=bt-rchild=NULL; while(in strcmp(fam[i].father,root)!=0) i++; if(in) { p=(BTree *)malloc(sizeof(BTree)); p-lchild=p-rchild=NULL; strcpy(p-name,fam[i].wife); bt-lchild=p; for(j=0;jn;j++) if(strcmp(fam[j].father,root)==0) { p-rchild=CreateBTree(fam[j].son,fam,n); p=p-rchild; } } return(bt); } void PrintBTree( BTree *bt ) //以广义表的形式输出二叉树BT { if(bt) { printf(%s,bt-name); if(bt-lchild||bt-rchild) { printf((); PrintBTree(bt-lchild); if(bt-rchild) p
显示全部
相似文档