#include < stdio.h >
#include < stdlib.h >
#include < string.h >#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -1#define MaxBookNum 1000 //假设只对1000本书建立索引表
#define MaxKeyNum 2500 //索引表的最大容量
#define MaxLineLen 500 //书目串的最大长度
#define MaxWordNum 10 //词表的最大容量
typedef int ElemType ; //定义链表数据元素类型为整型(书号类型)typedef struct
{
char *ch;
int length;
}HString;typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;void InitList(LinkList *L) ;
void PrintList(LinkList L) ;
ElemType GetElem(LinkList L, int i, ElemType *e) ;
int LocateElem(LinkList L,ElemType e) ;
void DestroyList(LinkList L) ;void InitString(HString *T) ;
void StrAssign( HString *T, char *cha) ;
void StrCopy( HString *T , HString S ) ;
void StrPrint(HString T, FILE *fp) ;
void ClearString(HString *T) ;
int StrCompare(HString S,HString T) ;//--------------------------------------------------------//
typedef struct {
char item[ 20 ][ 20 ] ; //字符串的数组
int last ; //词表的长度
} WordListType ; //词表类型(顺序表)typedef struct {
HString key ; //关键词
LinkList bnolist ; //存放书号索引的链表
} IdxTermType ; //索引项类型typedef struct {
IdxTermType item[ MaxKeyNum + 1 ] ;
int last ;
} IdxListType ; //索引表类型(有序表)//主要变量
char buf[ 256 ] ; //书目串缓冲区
WordListType wdlist ; //词表
HString oftenwords[ 7 ] ; //常用词表
//---------------------Basic Operation---------------------//void InitIdxList( IdxListType *idxlist ) ; //初始化,置索引表idxlist为空表,且在idxlist.item[0]设一空串
void GetLine( FILE *fp ) ; //从文件中读入一个书目信息到书目串缓冲区buf
void ExtractKeyWord( ElemType *bno ) ; //从书目串缓冲区提取书名关键词到词表wdlist,书号存入bno
int InsIdxList( IdxListType *idxlist , ElemType bno ) ; //将书号为bno的书名关键词按词典顺序插入索引表idxlist
void PutText( FILE *fp , IdxListType idxlist ) ; //将生成的索引表idxlist输入到文件中//---------------------For Insert--------------------------//
void GetWord( int i , HString *wd ) ; //用wd返回词表wdlist中第i个关键词
int Locate( IdxListType idxlist , HString wd , int *b );//在索引表idxlist中插叙是否存在与wd相等关键词.若存在,则返回其在索引表中的位置
第四章(5).建立词索引表
最新推荐文章于 2020-03-24 13:08:45 发布