已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
005 Computer Data Structure010 Introduction to Data Structure023 Fundamental of Data Structure034 The Design and Analysis of Computer Algorithms050 Introduction to Numerical Analysis067 Numerical Analysisalgorithms 034,analysis 034,050,067,computer 005,034,data 005,010,023,design 034,fundamental 023,introduction 010,050,numerical 050,067,structure 005,010,023,#include#include #include#include/函数结果状态代码#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2typedef int Status;typedef int Boolean;#define MaxBookNum1000/ 假设只对 1000 本书建立词索引表#define MaxKeyNum2500/ 索引表的最大容量#define MaxLineLen500/ 书目串的最大长度#define MaxWordNum10/ 词表的最大容量#define MaxWordLen 100/ 关键词的最大长度typedef struct char* ch;/ 若是非空串, 则按串长分配存储区, 否则 ch 为 NULLint length;/ 串长度HString;typedef struct char* itemMaxWordNum;/ 字符串的数组int last;/ 词表的长度WordListType;/ 词表类型(顺序表)typedef int ElemType;/ 定义链表的数据元素类型为整型(书号类型)typedef struct LNode ElemType data3;/ 书号(三位数字)struct LNode *next;/ 指向下一个书号*Link,*LinkList;typedef struct HString key;/ 关键词LinkList bnolist;/ 存放书号索引的链表IdxTermType;/ 索引项类型typedef struct IdxTermType itemMaxKeyNum + 1;int last;IdxListType;/ 索引表类型(有序表)/主要变量char* buf;/ 书目串缓冲区char cMaxLineLen;int BookNo3;/ 书号char * No=and,of,if,the,to,many,more; / 常用词表WordListType wdlist;/ 词表IdxListType idxlist;/ 索引表/*/基本操作Status StrAssign(HString &T, char* chars);/ 生成一个其值等于串常量 chars 的串 Tint StrCompare(HString S, HString T);/ 若 ST , 则返回值 0 ; 若 S=T , 则返回值 =0 ; 若 ST , 则返回值 0 ; void StrCopy(HString &S, HString &T);/ 复制 T 到 S void InitIdxList(IdxListType &idxlist);/ 初始化操作, 置索引表 idxlist 为空表, 且在 idxlist.item0 设一空串Status GetLine(FILE* f);/ 从文件 f 读入一个书目信息到书目串缓冲区 bufvoid ExtractKeyWord(ElemType &bno);/ 从 buf 中提取书名关键字到词表 wdlist, 书号存入 bnoStatus InsIdxList(IdxListType &idxlist, ElemType bno);/ 将书号为 bno 的书名关键词按词典顺序插入索引表 idxlistvoid PutText(FILE g, IdxListType idxlist);/ 将生成的索引表 idxlist 输出到文件 gStatus InitList(LinkList &L);/ 初始化书号索引表为空表void InitWordList(WordListType &wdlist);/ 初始化词表Status IsKeyWord(char *wd);/ 判断是否为关键词Status MakeNode(Link &t,ElemType e);/ 初始化新的书号索引结点Status Appand(LinkList &L,Link s);/ 在关键词后插入新的书号结点void GetWord(int i, HString &wd);/ 用 wd 返回词表 wdlist 中第 i 个关键词int Locate(IdxListType idxlist, HString wd, Boolean &b);/ 在索引表 idxlist 中查询是否存在与 wd 相等的关键词。 若存在,则返回其在/ 索引表中的位置, 且 b 取值 TRUE; 否则返回插入位置, 且 b 取值 FALSEvoid InsertNewKey(IdxListType &idxlist, int i, HString wd);/ 在索引表 idxlist 的第 i 项上插入新关键词 wd, 并初始化书号索引的链表为空表Status InsertBook(IdxListType &idxlist, int i, int bno);/ 在索引表 idxlist 的第 i 项中插入书号为 bno 的索引*/Status StrAssign(HString &T, char* chars) int i;char *c;if(T.ch)free(T.ch);/ 释放 T 原有的空间for(i=0, c=chars; c!=/0; i+,c+)printf(%c, c);/ 求 chars 的长度 iif(!i)T.ch = NULL;T.length = 0;else if(!(T.ch = (char*)malloc(i*sizeof(char)return OVERFLOW;T.length = i;for(i=0; iT.length; i+)T.chi = charsi;T.chi=/0;return OK;/ StrAssignint StrCompare(HString S, HString T)int i;for(i=0; iS.length & iT.length; i+)if(S.chi != T.chi)return S.chi - T.chi;return S.length - T.length;/ StrComparevoid StrCopy(HString &S,HString &T)int i;if(T.ch=NULL)S.ch=NULL;S.length=0;elsefor(i=0;iT.length;i+)S.chi=T.chi;S.chi=/0;S.length=T.length;/ StrCopyvoid GetWord(int i, HString &wd)/char* p;/p = *(wdlist.item + i);/ 取词表中第 i 个字符串/StrAssign(wd, p);/ 生成关键字字符串char *t=&(*wdlist.itemi);int n;for(n=0;*t!=/0;n+)t+;wd.length=n;for(n=0;n0; i-);if(m = 0) / 找到b = TRUE;return i;else b = FALSE;return i+1;/ LocateStatus InitList(LinkList &L) int i;if(!(L=(Link)malloc(sizeof(LNode)return OVERFLOW;for(i=0; idatai = (int)malloc(sizeof(int) return OVERFLOW;L-next=NULL;return OK;/ InitListvoid InsertNewKey(IdxListType &idxlist,int i,HString &wd)int j;for(j = idxlist.last-1; j=i; j-) / 后移索引项StrCopy(idxlist.itemj+1.key,idxlist.itemj.key);idxlist.itemj+1.bnolist = idxlist.itemj.bnolist;/ 插入新的索引项StrCopy(idxlist.itemi.key, wd);/ 串赋值InitList(idxlist.itemi.bnolist);/ 初始化书号索引表为空表idxlist.last +;/ InsertNewKeyStatus MakeNode(Link &t,ElemType e)int i;if(!(t = (Link)malloc(sizeof(LNode)return OVERFLOW;else for(i=0;idatai=ei;t-next=NULL;return OK;/ MakeNodeStatus Appand(LinkList &L,Link s)Link q = L;if(!s)return ERROR;while(q-next)q=q-next;q-next=s;return OK;/ AppandStatus InsertBook(IdxListType &idxlist, int i, int bno) Link p;if(!MakeNode(p, bno)return ERROR;/ 分配失败Appand(idxlist.itemi.bnolist, p);/ 插入新的书号索引return OK;/ InsertBookvoid Init_HString(HString &wd)wd.ch=(char *)malloc(MaxWordLen*sizeof(char);for(int e=0; eMaxWordLen; e+)wd.che=/0;wd.length=0;Status InsIdxList(IdxListType &idxlist, int bno) int i, j, b;HString wd;Init_HString(wd);for(i=0; iwdlist.last; i+)GetWord(i, wd);j = Locate(idxlist, wd, b);if(!b)InsertNewKey(idxlist, j, wd);/ 插入新的索引项if(!InsertBook(idxlist, j, bno)/ 插入书号索引return OVERFLOW;return OK;/ InsertIdxListStatus GetLine(FILE* f)int i;buf = c;if(!feof(f)for(i=0; (ci=fgetc(f)!=EOF&ci!=/n&iMaxLineLen; i+);ci=/0;return OK;else return ERROR;void InitWordList(WordListType &wdlist)int i,j;for(i=0;iMaxWordNum;i+)wdlist.itemi = (char *)malloc(MaxWordLen*sizeof(char);for(j=0; jMaxWordLen; j+)wdlist.itemij=/0;wdlist.last=0;Status IsKeyWord(char *wd)int i;for(i=0; Noi!=NULL; i+)if(!strcmp(Noi,wd)return FALSE;return TRUE;void ExtractKeyWord(int BookNo3) int i = 0,j,k;char charsMaxWordLen;while(*buf!= )BookNoi = *buf - 0;buf+;i+;InitWordList(wdlist);int m=0;for(i=0; *buf!=/0&wdlist.lastMaxWordNum;i+)while(*buf= )buf+;for(j=0; *buf!= &*buf!=/0&*(&(*buf)!=/n; j+)/if(isSupper(*buf)charsj = tolower(*buf);/else/charsj = *buf;buf+;charsj=/0;if(IsKeyWord(chars)for(k=0;kj;k+)wdlist.itemmk = charsk;m+;wdlist.last+;void PutText(FILE* g,IdxListType idxlist)int i,j;for(i=0; inext;while(t)for(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 浅析英文电影与高职英语教学-英文动画电影《花木兰》的教学设计
- 存在的问题的原因及整改措施
- 2025毕业论文阅卷人评语文档3
- 基于价值链的成本控制策略研究【开题报告】
- 工程合同协议书三篇范本(3篇)
- 毕业论文(设计)质量评价标准和要求
- 电大汉语言文学本科毕业论文范文2
- 信息安全技术论文题目(筛选标题100个)
- 学会科普工作存在的问题及解决对策
- 基于S7-200 Smart和V20的恒压供水系统优化设计
- (2025年)《计算机导论》期末考试试题模拟试题及答案
- 数字化种植管理
- 2025年大学《园林-园林植物栽培与养护》考试备考题库及答案解析
- 网络安全运维服务方案
- 农商行劳务合同范本
- 铁路线路及站场课件 项目四 中间站
- 购买林蛙养殖合同范本
- 2024人教版三年级美术上册第一单元《童年生活-美术作品欣赏》每课教案汇编(含三个教案)
- 声入人心:2025年播客行业报告
- 高校财务专项审计实施方案与报告
- 银行客户画像及风险评估模型
评论
0/150
提交评论