#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct SUBLINK
{
int index;
struct SUBLINK *next;
}sublink;
struct NODE
{
char feature[20];
int upnnum;
struct SUBLINK *upnode;
int fullfill;
int type;
int state;
int sonnum;
struct SUBLINK *sonnode;
}node;
#define MAXNUM 1000
struct NODE *nodelink[MAXNUM];
int nodenum;
void initiate();
void quarry();
void modify();
int extend(struct NODE *ntx);
int showfault() ;
void store();
void main()
{
int flag;
initiate();
for(;;)
{
printf("\n\t请选择操作:\n\n\t1、查询;\n\n\t2、添加新知识;\n\n\t3、退出程序.\n\n\t");
scanf("%d",&flag);
switch(flag)
{
case 1:
quarry();
break;
case 2:
modify();
break;
case 3:
store();
default:
printf("\n输入错误,请重新输入\n");
}
}
}
void initiate()//初始化
{
int i , j;
char s[10];
FILE *kf;
struct NODE *newnode;
struct SUBLINK *newlink , *oldlink;
if((kf = fopen("knowledgestore.txt" , "r")) == NULL)
{
printf("Cannot create/open file");
exit(1);
}
fscanf(kf , "%5d" , &nodenum);
for(i=0 ; i < nodenum ; i++)
{
newnode = (struct NODE*)malloc (sizeof(node));
if(newnode == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
fscanf(kf , "%20s" , newnode->feature);
fscanf(kf , "%5d" , &newnode->upnnum);
for(j=0 ; j<newnode->upnnum ; j++)
{
newlink = (struct SUBLINK*) malloc (sizeof(sublink));
if(newlink == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
fscanf(kf , "%5d" , &newlink->index);
if(j == 0)
newnode->upnode = oldlink = newlink;
newlink->next = NULL;
oldlink->next = newlink;
oldlink = newlink;
}
newnode->fullfill = 0;
newnode->state = 0;
fscanf(kf , "%5d" , &newnode->type);
fscanf(kf , "%5d" , &newnode->sonnum);
for(j=0 ; j < newnode->sonnum ; j++)
{
newlink = (struct SUBLINK*)malloc(sizeof(sublink));
if(newlink == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
fscanf(kf , "%5d" , &newlink->index);
if(j == 0)
newnode->sonnode = oldlink = newlink;
newlink->next = NULL;
oldlink->next = newlink;
oldlink = newlink;
}
nodelink[i] = newnode;
}
fscanf(kf , "%10s" , s);
if(strcmp(s , "end") != 0)
{
printf("\n程序初始化失败!");
exit(0);
}
}
void quarry()
{
struct NODE *ntx;
char feature[100];
int i , flag;
for(;;)
{
flag = 0;
printf("\n请输入动物的特征:");
scanf("%s" , feature);
for(i = 0 ; i < nodenum ; i++)
{
ntx = nodelink[i];
if(strstr(feature,ntx->feature) != NULL)
{
ntx->state = 1;
flag = extend(ntx);
}
}
if(flag >= 1)
{
for(i = 0 ; i < nodenum ; i++)
{
nodelink[i]->fullfill = 0;
nodelink[i]->state = 0;
}
break;
}
if(flag == 0)
if(showfault() == 0)break;
}
}
int extend(struct NODE *ntx)
{
int i , index;
int flag;
struct NODE *nextone;
struct SUBLINK *son;
if(ntx->sonnum == 0)
{
printf("\n结果为%20s\n" , ntx->feature);
return 1;
}
son = ntx->sonnode;
flag = 0;
for(i = 0 ; i < (ntx->sonnum) ; i++)
{
index = son->index;
nextone = nodelink[index];
if(nextone->type == 0)//或节点
{
if(nextone->state != 1)
{
nextone->state = 1;
printf("\n表明具有%20s特征" , nextone->feature);
flag += extend(nextone);
}
}
else
{
nextone->fullfill++;
if(nextone->fullfill == nextone->upnnum)
{
nextone->state = 1;
printf("\n表明具有%20s特征" , nextone->feature);
flag =+ extend(nextone);
}
}
son = son->next;
}
return flag;
}
void modify()
{
int i ;
char choice , feature[100];
struct NODE *ntx , *newnode;
struct SUBLINK *endl , *newl;
newnode = (struct NODE*)malloc(sizeof(node));
if(newnode == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
newnode->sonnum = 0;
newnode->upnnum = 0;
newnode->fullfill = 0;
printf("\n请输入新特征\n");
scanf("%s",newnode->feature);
printf("新特征类型:\n与节点(1),或节点(0)");
scanf("%d" , &newnode->type);
newnode->state = 0;
newnode->fullfill = 0;
for(;;)
{
printf("\n是否为叶节点?(Y/N)\n");
scanf("%s" , &choice);
choice = toupper(choice);
if(choice == 'N')
{
printf("\n请输入新特征描述的对象\n");
scanf("%s" , feature);
for(i = 0 ; i < nodenum ; i++)
{
ntx = nodelink[i];
if(strstr(feature,ntx->feature) != NULL)
{
newl = (struct SUBLINK*) malloc (sizeof(sublink));
if(newl == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
if(newnode->sonnum == 0)
newnode->sonnode = endl = newl;
newl->index = i;
endl->next = newl;
endl = newl;
newl->next = NULL;
newnode->sonnum++;
/////////////////////////////////将信息写入子节点
newl = (struct SUBLINK*) malloc (sizeof(sublink));
if(newl == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
if(ntx->upnnum == 0)
ntx->upnode = endl = newl;
newl->index = nodenum;
newl->next = ntx->upnode;
ntx->upnode = newl;
ntx->upnnum++;
}
}
break;
}
if(choice == 'Y')break;
}
for(;;)
{
printf("\n是否为顶点?(Y/N)\n");
scanf("%s" , &choice);
choice = toupper(choice);
if(choice == 'N')
{
printf("\n请输入对新对象的描述\n");
scanf("%s" , feature);
for(i = 0 ; i < nodenum ; i++)
{
ntx = nodelink[i];
if(strstr(feature , ntx->feature)!=NULL)
{
newl = (struct SUBLINK*) malloc (sizeof(sublink));
if(newl == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
if(newnode->upnnum == 0)
newnode->upnode = endl = newl;
newl->index = i;
endl->next = newl;
endl = newl;
newl->next = NULL;
newnode->upnnum++;
///////////////////////////////将信息写入父节点
newl = (struct SUBLINK*) malloc (sizeof(sublink));
if(newl == NULL)
{
printf("\n内存不够!\n");
exit(0);
}
if(ntx->sonnum == 0)
ntx->sonnode = endl = newl;
newl->index = nodenum;
newl->next = ntx->sonnode;
ntx->sonnode = newl;
ntx->sonnum++;
}
}
break;
}
if(choice == 'Y')break;
}
nodelink[nodenum] = newnode;
nodenum++;
}
void store()
{
int i , j;
char s[10];
FILE *kf;
struct NODE *writenode;
struct SUBLINK *newlink , *oldlink;
if((kf = fopen("knowledgestore.txt" , "w")) == NULL)
{
printf("Cannot create/open file");
exit(1);
}
fprintf(kf , "%5d" , nodenum);
for(i = 0 ; i < nodenum ; i++)
{
没有合适的资源?快使用搜索试试~ 我知道了~
经典数学函数程序(C语言实现)
共94个文件
cpp:88个
c:6个
需积分: 10 35 下载量 73 浏览量
2011-05-27
16:38:38
上传
评论
收藏 61KB RAR 举报
温馨提示
经典数学函数程序,可用于相关的数学方面的研究
资源推荐
资源详情
资源评论
收起资源包目录
经典数学函数程序.rar (94个子文件)
经典数学函数程序
数据的增减.cpp 2KB
数据运算.cpp 1KB
菱形.cpp 338B
矩阵的转置.cpp 686B
fseek.cpp 417B
chararr.c 338B
简单指针.cpp 209B
自加自减运算.cpp 314B
求和.cpp 470B
学生成绩输出.cpp 2KB
产生随机数.cpp 642B
三数排序.cpp 469B
函数排序.cpp 490B
多进制的输出.cpp 660B
指针.cpp 1KB
拟合多项式.cpp 4KB
运算.cpp 590B
sin(x).cpp 2KB
字符串字母排序.cpp 539B
信息查找.cpp 440B
条件语句.cpp 554B
整数排序.cpp 2KB
输入学生成绩并显示.cpp 729B
求高次方程.cpp 2KB
输出.cpp 341B
switch语句.cpp 2KB
比较字符.cpp 479B
integration1.c 1KB
排序.cpp 579B
拉格朗日插值.cpp 933B
查找信息.cpp 3KB
混合运算.cpp 387B
用指向指针的指针变量访问一维和二维数组.cpp 791B
微分方程.cpp 3KB
矩阵的逆.cpp 1KB
计算一年内的第多少天.cpp 680B
函数收敛.cpp 7KB
写文件.cpp 523B
init.c 456B
time.cpp 274B
排序的过程.cpp 965B
递归法将整数转换成字符.cpp 312B
计算月内的天数.cpp 452B
链表操作.cpp 3KB
jump.cpp 473B
转义字符的运用.cpp 330B
文件.cpp 629B
树.cpp 1KB
简单条件语句.cpp 316B
字符与数据运算.cpp 394B
神经网络拟合函数.cpp 5KB
倒置数组.cpp 526B
outer.cpp 344B
傅立叶函数.cpp 6KB
countdown.cpp 492B
time.c 274B
Newton迭代法.cpp 794B
计算天数.cpp 989B
学籍系统.cpp 1KB
矩阵.cpp 783B
解微分方程.cpp 2KB
枚举类型.cpp 2KB
个人信息查找.cpp 2KB
求公约数和公倍数.cpp 387B
共用体.cpp 260B
结构体的表示.cpp 521B
数学运算.cpp 266B
用弦截法求解方程的根.cpp 708B
数据交换.cpp 324B
创建整形链表.cpp 901B
学生成绩统计.cpp 2KB
文件储存.cpp 579B
微积分.cpp 1KB
输出数据.cpp 614B
文件运算.cpp 4KB
解方程.cpp 2KB
AI.C 7KB
移位运算.cpp 333B
文件信息.cpp 4KB
classify.c 9KB
三角形的面积计算.cpp 455B
字符数组的输入.cpp 638B
查错.cpp 1KB
结构体.cpp 524B
数据提取.cpp 1KB
位运算.cpp 239B
文件资料.cpp 9KB
字符的大小写转化.cpp 278B
查字.cpp 1KB
查找.cpp 546B
将字符串a复制到字符串b.cpp 318B
求sin(x)的值.cpp 311B
文件的操作.cpp 439B
整数的素数分解.cpp 697B
共 94 条
- 1
资源评论
LceChan
- 粉丝: 169
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功