云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 数据结构课程设计之简易家谱 报告

数据结构课程设计之简易家谱 报告

  • 62 次阅读
  • 3 次下载
  • 2025/5/2 16:37:41

课程设计(论文)

附录一:程序源代码

#include #include #include #include

#define NAME_length 50 //名字最大长度 #define LINE_length 100 //文本行最大长度 typedef struct cc {

struct cc *child, *next;//next指向同辈份的人物 char Name[]; }JPNode;

void clear(char p[],int n) //清空字符数组p { }

static JPNode *last = NULL; static int last_level = 0;

void AddJP(JPNode **head, char const name[], int level) {

JPNode **s = head, *r = NULL;

JPNode *p = (JPNode *)malloc( 2*sizeof(void *) + strlen(name) + 1 ); p->child = p->next = NULL; strcpy(p->Name,name); while(n-- > 0)

*p++ = '\\0';

if( *s == NULL)

{

16

课程设计(论文)

}

*s = p; last = p; return;

if(level - last_level == 1) {last->child = p; last =

p;last_level = level;return;}

if((level == last_level) && (*s != NULL)){last->next = p; last =

p;last_level = level;return;}

r = *s; //r指向家谱树 last_level = level;

while( level-- > 0) //找到相同的辈分 {

while(r->next != NULL)r = r->next; r = r->child;

}//以兄弟连接

while( r->next != NULL) r = r->next; r->next = p;

last = p; }

void CreatJP(JPNode **head) {

char name[NAME_length]=\

char *p = NULL;

int level=0,i=0; //辈分,以制表符个

数表示

FILE *fp = NULL;

fp = fopen(\

if(fp == NULL){ printf(\ while(level=0, i=0, fgets(line,LINE_length,fp) != NULL)

17

课程设计(论文)

{

p = line;

while(*p++ == '\\t')level++; //计算辈分 ,计算完后p指向名字开始处

while(line[i++] != '\\n')

;

line[i-1]='\\0'; //读入的换行符用字符串结束标识

符替换 }

void DispJP(JPNode *p)//从p指向的结点显示该家族 {

static int level=0; int i; }

fclose(fp);

strcpy(name,p-1);

AddJP(head,name,level);

clear(name,NAME_length); clear(line,LINE_length);

if(p != NULL)

{

for(i=0;i

}

else return; level++;

DispJP(p->child); }

level--;

DispJP(p->next);

18

课程设计(论文)

///////////////////////////////////////////////////////////////////////////

/*在家谱中添加新成员,并追加到文件中*/

int Equal(char const *p,char const q[])//判断两个字符串是否相等 { }

JPNode *Find_Name(JPNode *s, char *parent)//定位家谱中的成员。返回其指针(地址) {

static JPNode *here = NULL; if(s == NULL)return here;

if(Equal(s->Name,parent) == 1)return (here=s);

while(*p++ == *q++)if(*p == '\\0' && *q == '\\0')return (1); return (0);

here = Find_Name(s->child,parent); }

void Print_FILE(JPNode *p,FILE *fp) {

static int level=0;

int i;

here = Find_Name(s->next,parent); return here;

if(p != NULL)

{

for(i=0;i

}

else return; level++;

19

搜索更多关于: 数据结构课程设计之简易家谱 报告 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

课程设计(论文) 附录一:程序源代码 #include #include #include #include #define NAME_length 50 //名字最大长度 #define LINE_length 100 //文本行最大长度 typedef struct cc { struct cc *child, *next;//next指向同辈份的人物 char Name[]; }JPNode; void clear(char p[],int n) //清空字符数组p { } static JPNode *last = NULL; st

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com