diff --git a/CLion/CourseBook/0404_KMP/CMakeLists.txt b/CLion/CourseBook/0404_KMP/CMakeLists.txt new file mode 100644 index 0000000..72f0c1b --- /dev/null +++ b/CLion/CourseBook/0404_KMP/CMakeLists.txt @@ -0,0 +1,7 @@ +# 包含公共库 +include_directories(${CMAKE_SOURCE_DIR}/Status) + +# 生成可执行文件 +add_executable(KMP SString.h SString.c KMP.h KMP.c KMP-main.c) +# 链接公共库 +target_link_libraries(KMP Scanf_lib) \ No newline at end of file diff --git a/CLion/CourseBook/0404_KMP/KMP-main.c b/CLion/CourseBook/0404_KMP/KMP-main.c new file mode 100644 index 0000000..973e0d8 --- /dev/null +++ b/CLion/CourseBook/0404_KMP/KMP-main.c @@ -0,0 +1,64 @@ +#include "KMP.h" //**▲04 串**// + +// 测试函数,打印字符串 +void PrintElem(SString S); + +int main(int argc, char** argv) { + char* s = "abaaabcaabaabcacabaabcaabaabcac"; + char* t = "abaabcac"; + SString S, T; + int* next; // 模式串的next函数值 + int* nextval; // 模式串的nextval函数值 + int pos; // 匹配起点 + int i, j; + + StrAssign(S, s); // 初始化主串 + printf("S = "); + PrintElem(S); + + StrAssign(T, t); // 初始化模式串 + printf("T = "); + PrintElem(T); + + + // 注:next数组和nextval数组的0号单元是弃用的,从1号单元开始存储有效数据 + next = (int*) malloc((T[0] + 1) * sizeof(int)); + nextval = (int*) malloc((T[0] + 1) * sizeof(int)); + + get_next(T, next); // 算法4.7 + get_nextval(T, nextval); // 算法4.8,即算法4.7的改进版 + + printf("next : "); + for(i = 1; i <= T[0]; i++) { + printf("%d", next[i]); + } + printf("\n"); + + printf("nextval : "); + for(i = 1; i <= T[0]; i++) { + printf("%d", nextval[i]); + } + printf("\n"); + + + pos = 1; + + i = Index_KMP(S, T, pos, next); + j = Index_KMP(S, T, pos, nextval); + + printf("从%d个字符起,T 在 S 中第一次匹配成功的位置为 %d\n", pos, i); + printf("从%d个字符起,T 在 S 中第一次匹配成功的位置为 %d\n", pos, j); + + return 0; +} + +// 测试函数,打印字符串 +void PrintElem(SString S) { + int i; + + for(i = 1; i <= S[0]; i++) { + printf("%c", S[i]); + } + + printf("\n"); +} diff --git a/CLion/CourseBook/0404_KMP/KMP.c b/CLion/CourseBook/0404_KMP/KMP.c new file mode 100644 index 0000000..407ce55 --- /dev/null +++ b/CLion/CourseBook/0404_KMP/KMP.c @@ -0,0 +1,106 @@ +/*======================= + * KMP算法 + * + * 包含算法: 4.6、4.7、4.8 + ========================*/ + +#include "KMP.h" //**▲04 串**// + +/* + * ████████ 算法4.6 ████████ + * + * 查找 + * + * 从pos处开始搜索模式串T在主串S中首次出现的位置,如果不存在,则返回0。 + * 如果查找成功,返回匹配的位置。 + * + *【注】 + * 1.该实现用到了KMP算法,是一种比较高效的字符串匹配方式 + * 2.教材中没有next参数 + */ +int Index_KMP(SString S, SString T, int pos, int next[]) { + int i = pos; + int j = 1; + + if(pos < 1) { + return 0; + } + + // 比较字符串 + while(i <= S[0] && j <= T[0]) { + /* + * 两种情形: + * 1.在模式串的第一个字符处就失配 + * 2.主串和模式串处的字符相等 + */ + if(j == 0 || S[i] == T[j]) { + i++; + j++; + } else { + // 失配时回到前一个适当的位置 + j = next[j]; + } + } + + if(j > T[0]) { + // 匹配成功,返回匹配位置 + return i - T[0]; + } else { + // 匹配失败 + return 0; + } +} + +/* + * ████████ 算法4.7 ████████ + * + * 计算模式串的“失配数组”,用于KMP算法。 + */ +void get_next(SString T, int next[]) { + int i = 1; + int j = 0; + + // 模式串第一个字符处失配时,模式串需要从头比较,主串需要前进到下一个位置比较 + next[1] = 0; + + // 遍历模式串上的字符 + while(i < T[0]) { + if(j == 0 || T[i] == T[j]) { + i++; + j++; + next[i] = j; + } else { + j = next[j]; + } + } +} + +/* + * ████████ 算法4.8 ████████ + * + * 计算模式串的“失配数组”,用于KMP算法。 + * 这是一个优化后的版本,效率较算法4.7有所提高。 + */ +void get_nextval(SString T, int nextval[]) { + int i = 1; + int j = 0; + + // 模式串第一个字符处失配时,模式串需要从头比较,主串需要前进到下一个位置比较 + nextval[1] = 0; + + // 遍历模式串上的字符 + while(i < T[0]) { + if(j==0 || T[i] == T[j]) { + i++; + j++; + + if(T[i] != T[j]) { + nextval[i] = j; + } else { + nextval[i] = nextval[j]; + } + } else { + j = nextval[j]; + } + } +} diff --git a/CLion/CourseBook/0404_KMP/KMP.h b/CLion/CourseBook/0404_KMP/KMP.h new file mode 100644 index 0000000..040e05a --- /dev/null +++ b/CLion/CourseBook/0404_KMP/KMP.h @@ -0,0 +1,43 @@ +/*======================= + * KMP算法 + * + * 包含算法: 4.6、4.7、4.8 + ========================*/ + +#ifndef KMP_H +#define KMP_H + +#include +#include +#include "SString.h" //**▲04 串**// + +/* + * ████████ 算法4.6 ████████ + * + * 查找 + * + * 从pos处开始搜索模式串T在主串S中首次出现的位置,如果不存在,则返回0。 + * 如果查找成功,返回匹配的位置。 + * + *【注】 + * 1.该实现用到了KMP算法,是一种比较高效的字符串匹配方式 + * 2.教材中没有next参数 + */ +int Index_KMP(SString S, SString T, int pos, int next[]); + +/* + * ████████ 算法4.7 ████████ + * + * 计算模式串的“失配数组”,用于KMP算法。 + */ +void get_next(SString T, int next[]); + +/* + * ████████ 算法4.8 ████████ + * + * 计算模式串的“失配数组”,用于KMP算法。 + * 这是一个优化后的版本,效率较算法4.7有所提高。 + */ +void get_nextval(SString T, int nextval[]); + +#endif diff --git a/CLion/CourseBook/0404_KMP/SString.c b/CLion/CourseBook/0404_KMP/SString.c new file mode 100644 index 0000000..6097188 --- /dev/null +++ b/CLion/CourseBook/0404_KMP/SString.c @@ -0,0 +1,33 @@ +/*============================= + * 串的定长顺序存储表示(顺序串) + * + * 包含算法: 4.1、4.2、4.3、4.5 + ==============================*/ + +#include "SString.h" //**▲04 串**// + +/* + * 初始化 + * + * 构造一个值为chars的串T。 + * + *【注】 + * 该操作属于最小操作子集 + */ +Status StrAssign(SString T, const char* chars) { + int i, len; + + len = (int) strlen(chars); + + // chars过长 + if(len > MAXSTRLEN) { + return ERROR; + } + + T[0] = len; + for(i = 1; i <= len; i++) { + T[i] = chars[i - 1]; + } + + return OK; +} diff --git a/CLion/CourseBook/0404_KMP/SString.h b/CLion/CourseBook/0404_KMP/SString.h new file mode 100644 index 0000000..5aed54f --- /dev/null +++ b/CLion/CourseBook/0404_KMP/SString.h @@ -0,0 +1,36 @@ +/*============================= + * 串的定长顺序存储表示(顺序串) + * + * 包含算法: 4.1、4.2、4.3、4.5 + ==============================*/ + +#ifndef SSTRING_H +#define SSTRING_H + +#include +#include // 提供strlen原型 +#include "Status.h" //**▲01 绪论**// + +/* 宏定义 */ +#define MAXSTRLEN 255 // 顺序串的最大串长 + +/* + * 串的顺序存储类型定义 + * + * 注:有效元素从SString的1号单元开始存储 + * SString的0号单元用来存储其长度 + */ +typedef unsigned char SString[MAXSTRLEN + 1]; // 0号单元存放串的长度 + + +/* + * 初始化 + * + * 构造一个值为chars的串T。 + * + *【注】 + * 该操作属于最小操作子集 + */ +Status StrAssign(SString T, const char* chars); + +#endif diff --git a/CLion/CourseBook/0405_WordList/CMakeLists.txt b/CLion/CourseBook/0405_WordList/CMakeLists.txt new file mode 100644 index 0000000..ef86736 --- /dev/null +++ b/CLion/CourseBook/0405_WordList/CMakeLists.txt @@ -0,0 +1,12 @@ +# 包含公共库 +include_directories(${CMAKE_SOURCE_DIR}/Status) + +# 生成可执行文件 +add_executable(WordList ELinkList.h ELinkList.c HString.h HString.c WordList.h WordList.c WordList-main.c) +# 链接公共库 +target_link_libraries(WordList Scanf_lib) + +# 记录要拷贝到*.exe目录下的资源文件 +file(GLOB TestData TestData*.txt) +# 将资源文件拷贝到*.exe目录下,不然无法加载 +file(COPY ${TestData} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/CLion/CourseBook/0405_WordList/ELinkList.c b/CLion/CourseBook/0405_WordList/ELinkList.c new file mode 100644 index 0000000..32b3a55 --- /dev/null +++ b/CLion/CourseBook/0405_WordList/ELinkList.c @@ -0,0 +1,95 @@ +/*======================= + * 扩展的单链表(线性链表) + * + * 包含算法: 2.20 + ========================*/ + +#include "ELinkList.h" //**▲02 线性表**// + + +/*━━━━━━━━━━━━━━━━━━━━━━ 内存操作 ━━━━━━━━━━━━━━━━━━━━━━*/ + +/* + * 内存分配 + * + * 为线性链表申请一个结点,并存入指定的数据e。 + * + *【备注】 + * static修饰的含义是该函数仅限当前文件内使用 + */ +Status MakeNode(Link* p, ElemType e) { + if(p == NULL) { + return ERROR; + } + + // 申请空间 + *p = (Link) malloc(sizeof(LNode)); + if(*p == NULL) { + // 这里没有退出程序,而是返回错误提示 + return ERROR; + } + + (*p)->data = e; + (*p)->next = NULL; + + return OK; +} + + +/*━━━━━━━━━━━━━━━━━━━━━━ 链表常规操作 ━━━━━━━━━━━━━━━━━━━━━━*/ + +/* + * 初始化 + * + * 初始化成功则返回OK,否则返回ERROR。 + */ +Status InitList(ELinkList* L) { + Link p; + + if(L == NULL) { + return ERROR; + } + + // 创建头结点 + p = (Link) malloc(sizeof(LNode)); + if(p == NULL) { + exit(OVERFLOW); + } + p->next = NULL; + + // 只有头结点时,首位游标指向自身 + (*L).head = (*L).tail = p; + (*L).len = 0; + + return OK; +} + + +/*━━━━━━━━━━━━━━━━━━━━━━ 链表扩展操作 ━━━━━━━━━━━━━━━━━━━━━━*/ + +/* + * 向尾部添加 + * + * 将s所指的一串结点链接在链表L后面 + */ +Status Append(ELinkList* L, Link s) { + int count; + + if(L == NULL || (*L).head == NULL || s == NULL) { + return ERROR; + } + + count = 0; + (*L).tail->next = s; + + // 确定新的尾结点位置 + while(s != NULL) { + (*L).tail = s; + s = s->next; + count++; + } + + (*L).len += count; + + return OK; +} diff --git a/CLion/CourseBook/0405_WordList/ELinkList.h b/CLion/CourseBook/0405_WordList/ELinkList.h new file mode 100644 index 0000000..8340204 --- /dev/null +++ b/CLion/CourseBook/0405_WordList/ELinkList.h @@ -0,0 +1,75 @@ +/*======================= + * 扩展的单链表(线性链表) + * + * 包含算法: 2.20 + ========================*/ + +#ifndef ELINKLIST_H +#define ELINKLIST_H + +#include +#include // 提供malloc、realloc、free、exit原型 +#include // 提供一些极限常量 +#include "Status.h" //**▲01 绪论**// + +/* + * ████ 注意 ████ + * + * 教材中的线性链表命名为LinkList, + * 这里为了与单链表区分,故将其命名为ELinkList。 + * 线性链表可以理解成对普通链表的一种扩展。 + */ + +/* 线性链表元素类型定义 */ +typedef int ElemType; + +/* + * 线性链表结构 + * + * 注:这里的线性链表存在头结点 + */ +typedef struct LNode { + ElemType data; + struct LNode* next; +} LNode, * Link, * Position; + +/* 维护线性链表头尾指针及长度信息 */ +typedef struct { + Link head, tail; // 分别指向线性链表中的头结点和尾结点 + int len; // 指示线性链表中数据元素的个数 +} ELinkList; + + +/*━━━━━━━━━━━━━━━━━━━━━━ 内存操作 ━━━━━━━━━━━━━━━━━━━━━━*/ + +/* + * 内存分配 + * + * 为线性链表申请一个结点,并存入指定的数据e。 + * + *【备注】 + * static修饰的含义是该函数仅限当前文件内使用 + */ +Status MakeNode(Link* p, ElemType e); + + +/*━━━━━━━━━━━━━━━━━━━━━━ 链表常规操作 ━━━━━━━━━━━━━━━━━━━━━━*/ + +/* + * 初始化 + * + * 初始化成功则返回OK,否则返回ERROR。 + */ +Status InitList(ELinkList* L); + + +/*━━━━━━━━━━━━━━━━━━━━━━ 链表扩展操作 ━━━━━━━━━━━━━━━━━━━━━━*/ + +/* + * 向尾部添加 + * + * 将s所指的一串结点链接在链表L后面 + */ +Status Append(ELinkList* L, Link s); + +#endif diff --git a/CLion/CourseBook/0405_WordList/HString.c b/CLion/CourseBook/0405_WordList/HString.c new file mode 100644 index 0000000..12a8f36 --- /dev/null +++ b/CLion/CourseBook/0405_WordList/HString.c @@ -0,0 +1,95 @@ +/*========================= + * 串的堆分配存储表示(堆串) + * + * 包含算法: 4.4 + ==========================*/ + +#include "HString.h" //**▲04 串**// + +/* + * 初始化 + * + * 构造一个值为chars的串T。 + * + *【注】 + * 该操作属于最小操作子集 + */ +Status StrAssign(HString* T, const char* chars) { + int i, j; + + // 求chars的长度 + i = (int) strlen(chars); + + // 没有有效元素 + if(i == 0) { + (*T).ch = NULL; + (*T).length = 0; + + return OK; + } + + // 存在有效元素时,需要分配存储空间 + (*T).ch = (char*) malloc(i * sizeof(char)); + if(!((*T).ch)) { + exit(OVERFLOW); + } + + for(j = 0; j < i; j++) { + (*T).ch[j] = chars[j]; + } + + (*T).length = i; + + return OK; +} + +/* + * 比较 + * + * 比较串S和串T,返回比较结果。 + * + *【注】 + * 该操作属于最小操作子集 + */ +Status StrCompare(HString S, HString T) { + int i; + + for(i = 0; i < S.length && i < T.length; i++) { + // 遇到不同的字符时,比较其大小 + if(S.ch[i] != T.ch[i]) { + return S.ch[i] - T.ch[i]; + } + } + + return S.length - T.length; +} + +/* + * 复制 + * + * 将串S复制到串T。 + */ +Status StrCopy(HString* T, HString S) { + int i; + + if(S.length == 0) { + (*T).ch = NULL; + (*T).length = 0; + } else { + // 分配空间 + (*T).ch = (char*) malloc(S.length * sizeof(char)); + if(!(*T).ch) { + exit(OVERFLOW); + } + + // 复制元素 + for(i = 0; i < S.length; i++) { + (*T).ch[i] = S.ch[i]; + } + + // 复制长度信息 + (*T).length = S.length; + } + + return OK; +} diff --git a/CLion/CourseBook/0405_WordList/HString.h b/CLion/CourseBook/0405_WordList/HString.h new file mode 100644 index 0000000..e55ac5c --- /dev/null +++ b/CLion/CourseBook/0405_WordList/HString.h @@ -0,0 +1,53 @@ +/*========================= + * 串的堆分配存储表示(堆串) + * + * 包含算法: 4.4 + ==========================*/ + +#ifndef HSTRING +#define HSTRING + +#include +#include // 提供malloc、realloc、free、exit原型 +#include // 提供strlen原型 +#include "Status.h" //**▲01 绪论**// + +/* + * 串的堆存储表示 + * + * 注:有效元素从ch的0号单元开始存储 + */ +typedef struct { + char* ch; // 若是非空串,则按串长分配存储区,否则ch为NULL + int length; +} HString; + + +/* + * 初始化 + * + * 构造一个值为chars的串T。 + * + *【注】 + * 该操作属于最小操作子集 + */ +Status StrAssign(HString* T, const char* chars); + +/* + * 比较 + * + * 比较串S和串T,返回比较结果。 + * + *【注】 + * 该操作属于最小操作子集 + */ +Status StrCompare(HString S, HString T); + +/* + * 复制 + * + * 将串S复制到串T。 + */ +Status StrCopy(HString* T, HString S); + +#endif diff --git a/CLion/CourseBook/0405_WordList/TestData.txt b/CLion/CourseBook/0405_WordList/TestData.txt new file mode 100644 index 0000000..fcf256f --- /dev/null +++ b/CLion/CourseBook/0405_WordList/TestData.txt @@ -0,0 +1,7 @@ +书 号 书 名 + 005 Computer Data Structures + 010 Introduction to Data Structures + 023 Fundamentals of Data Structures + 034 The Design and Analysis of Computer Algorithms + 050 Introduction to Numerical Analysis + 067 Numerical Analysis diff --git a/CLion/CourseBook/0405_WordList/WordList-main.c b/CLion/CourseBook/0405_WordList/WordList-main.c new file mode 100644 index 0000000..a5f5f60 --- /dev/null +++ b/CLion/CourseBook/0405_WordList/WordList-main.c @@ -0,0 +1,27 @@ +#include // 提供system原型 +#include "WordList.h" //**▲04 串**// + +int main(int argc, char** argv) { + FILE* fp; + char line[MaxLineLen]; + + char* bookinfo = "TestData.txt"; // 书目文件名 + char* bookidx = "BookIdx.txt"; // 关键词索引文件名 + + // 创建索引表 + Main(bookinfo, bookidx); + + // 显示索引表到屏幕 + if((fp = fopen(bookidx, "r"))!=NULL) { + printf("---------索引表生成功!---------\n\n"); + + while(feof(fp)==FALSE) { + fgets(line, MaxLineLen, fp); + printf("%s", line); + } + } else { + printf("---------未发现索引表!---------\n"); + } + + return 0; +} diff --git a/CLion/CourseBook/0405_WordList/WordList.c b/CLion/CourseBook/0405_WordList/WordList.c new file mode 100644 index 0000000..b9e5a94 --- /dev/null +++ b/CLion/CourseBook/0405_WordList/WordList.c @@ -0,0 +1,308 @@ +/*=========================================== + * 索引表 + * + * 包含算法: 4.9、4.10、4.11、4.12、4.13、4.14 + ============================================*/ + +#include "WordList.h" //**▲04 串**// + +/* + * ████████ 算法4.9 ████████ + * + * 从文件bookinfo中读取书目信息,并依此创建相应的关键词索引表,然后将索引表写入文件bookidx。 + */ +void Main(char* bookinfo, char* bookidx) { + FILE* f, * g; + char head[MaxLineLen]; // 书目的表头信息(未使用) + IdxListType idxlist; // 关键词索引表 + ElemType bno; // 书号 + int count; + + // 以“只读”模式打开书目文件 + if((f = fopen(bookinfo, "r")) != NULL) { + + // 以“只写”模式打开索引文件 + if((g = fopen(bookidx, "w")) != NULL) { + + // 初始化索引表 + InitIdxList(&idxlist); + + // 跳过文件第一行 + fgets(head, MaxLineLen, f); + + count = 0; + + // 如果未到文件结尾,则一直读文件 + while(feof(f) == FALSE && count < MaxBookNum) { + + // 从文件f读入一个书目信息到书目缓冲区gBuf + GetLine(f); + + // 从gBuf提取关键词到词表gWdList,书号存入bno + ExtractKeyWord(&bno); + + // 将书号及对应的关键词插入索引表idxlist + InsIdxList(&idxlist, bno); + + count++; + } + + // 向文件g中写入索引表数据 + PutText(g, idxlist); + + fclose(g); + } + + fclose(f); + } +} + +/* + * 初始化索引表 + * + *【注】 + * 教材中将索引表表头置为空串,但这里设定了一个有意义的表头 + */ +void InitIdxList(IdxListType* idxlist) { + // 索引表的表头信息 + char* chars = "关键词 书号索引"; + IdxTermType e; + + // 初始化表头信息 + StrAssign(&(e.key), chars); + + // 初始化书号索引链表 + InitList(&(e.bnolist)); + + (*idxlist).item[0] = e; + + // 表头为第0条信息 + (*idxlist).last = 0; +} + +/* + * 从文件f中读取一条书目信息存入书目缓冲区gBuf。 + */ +void GetLine(FILE* f) { + // 读取一行数据,存入缓冲区gBuf + fgets(gBuf, MaxLineLen, f); +} + +/* + * 从缓冲区gBuf中提取书名关键词到词表gWdList,书号存入bno。 + */ +void ExtractKeyWord(ElemType* bno) { + char delim[] = {'-', ' ', '\r', '\n', '\t'}; // 分隔符 + char* title; // 书名 + char* token; // 从书名中分解出的关键词 + + // 分解书目字符串,将书号存入bno(十进制),并用title指向剩下的字符串(书名) + *bno = (int) strtol(gBuf, &title, 10); + + // 将书名的由大写变小写 + strlwr(title); + + // 清空关键词词表 + gWdList.last = 0; + + // 分解关键词 + for(token = strtok(title, delim); token != NULL; token = strtok(NULL, delim)) { + // 如果该关键词是常用词,则忽略它 + if(isCommonWords(token) == TRUE) { + continue; + } + + // 记下从书名中提取的关键词 + gWdList.item[gWdList.last++] = token; + } +} + +/* + * ████████ 算法4.10 ████████ + * + * 将书号bno对应的书名中的关键词按词典顺序插入到索引表idxlist。 + */ +Status InsIdxList(IdxListType* idxlist, int bno) { + int i, j; + Boolean boo; + HString wd; + + if(gWdList.last <= 0) { + return ERROR; + } + + // 遍历书号bno对应的书名中的所有关键词 + for(i = 0; i < gWdList.last; i++) { + // 获取待插入的关键词 + GetWord(i, &wd); + + // 判断该关键词是否已经位于索引表中 + j = Locate(*idxlist, wd, &boo); + + // 如果该关键词不在索引表中,则需要插入关键词 + if(boo == FALSE) { + // 将关键词wd插入到索引表 + InsertNewKey(idxlist, j, wd); + } + + // 在关键词已存在的情形下,插入书号 + if(!InsertBook(idxlist, j, bno)) { + return ERROR; + } + } + + return OK; +} + +/* + * ████████ 算法4.11 ████████ + * + * 用wd返回词表gWdList中第i个关键词。 + */ +void GetWord(int i, HString* wd) { + if(i < 0 || i > gWdList.last - 1) { + StrAssign(wd, ""); + } else { + StrAssign(wd, gWdList.item[i]); + } +} + +/* + * ████████ 算法4.12 ████████ + * + * 查询在索引表idxlist中是否存在与wd相等的关键词。 + * 若存在,则返回wd在词表中的位置,并置b为TRUE。 + * 若不存在,则返回wd应插入的位置,并置b为FALSE。 + */ +int Locate(IdxListType idxlist, HString wd, Boolean* b) { + int i, m = -1; + + /* + * 在索引表idxlist中查找关键词wd是否存在 + * 注:0号单元存储了表头信息 + */ + for(i = idxlist.last; i > 0 && (m = StrCompare(idxlist.item[i].key, wd)) > 0; i--) { + } + + // 如果找到了关键词wd + if(m == 0) { + *b = TRUE; + return i; + } else { + *b = FALSE; + return i + 1; + } +} + +/* + * ████████ 算法4.13 ████████ + * + * 在索引表的索引i(>=0)处插入关键词wd,并初始化书号索引的链表为空表。 + */ +void InsertNewKey(IdxListType* idxlist, int i, HString wd) { + int j; + + /* + * 索引项后移 + * 注:0号单元存储了表头信息 + */ + for(j = (*idxlist).last; j >= i; j--) { + (*idxlist).item[j + 1] = (*idxlist).item[j]; + } + + // 插入索引项 + StrCopy(&((*idxlist).item[i].key), wd); + + // 初始化书号索引链表 + InitList(&((*idxlist).item[i].bnolist)); + + // 索引数目增一 + (*idxlist).last++; +} + +/* + * ████████ 算法4.14 ████████ + * + * 为索引表在索引i(>0)处的关键词插入书号。 + */ +Status InsertBook(IdxListType* idxlist, int i, ElemType bno) { + Link p; + + // 内存分配失败 + if(MakeNode(&p, bno) == FALSE) { + return ERROR; + } + + // 插入新的书号索引 + Append(&((*idxlist).item[i].bnolist), p); + + return OK; +} + +/* + * 将生成的索引表idxlist输出到文件g。 + */ +void PutText(FILE* g, IdxListType idxlist) { + int i, j, m, n; + Link p; + HString S; + ELinkList L; + + if(idxlist.last <= 0) { + return; + } + + // 先输出表头信息 + S = idxlist.item[0].key; + for(m = 0; m < S.length; m++) { + fprintf(g, "%c", S.ch[m]); + } + fprintf(g, "\n"); + + // 输出索引信息 + for(i = 1; i <= idxlist.last; i++) { + // 1.输出关键词 + S = idxlist.item[i].key; + for(m = 0; m < S.length; m++) { + fprintf(g, "%c", S.ch[m]); + } + + // 2.输出空格 + for(j = 1; j <= 18 - idxlist.item[i].key.length; j++) { + fprintf(g, " "); + } + + // 3.输出书号索引 + L = idxlist.item[i].bnolist; + for(n = 1, p = L.head->next; n <= L.len; n++) { + fprintf(g, "%03d", p->data); + p = p->next; + if(p) { + fprintf(g, ","); + } + } + + // 4.输出换行 + fprintf(g, "\n"); + } + +} + +// 判断str是否为常用词 +static Status isCommonWords(char* str) { + int i; + + // 常用词词表,这些词汇会被排除在关键词之外 + WordListType words = {{"a", "an", "the", "of", "and", "is", "to", "as", "in", "for"}, 10}; + + // 查询常用词词表 + for(i = 0; i < words.last; i++) { + // 对两字符串进行忽略大小写的比较 + if(strcasecmp(str, words.item[i]) == 0) { + // 如果该字符串是常用词,则返回TRUE + return TRUE; + } + } + + return FALSE; +} diff --git a/CLion/CourseBook/0405_WordList/WordList.h b/CLion/CourseBook/0405_WordList/WordList.h new file mode 100644 index 0000000..0a6fdcd --- /dev/null +++ b/CLion/CourseBook/0405_WordList/WordList.h @@ -0,0 +1,130 @@ +/*=========================================== + * 索引表 + * + * 包含算法: 4.9、4.10、4.11、4.12、4.13、4.14 + ============================================*/ + +#ifndef WORDLIST_H +#define WORDLIST_H + +#include // 提供fopen、fclose、feof、fgets原型 +#include // 提供exit、strtol原型 +#include // 提供strlen、strcmpi、strlwr原型 +#include "Status.h" //**▲01 绪论**// +#include "ELinkList.h" //**▲02 线性表**// +#include "HString.h" //**▲04 串**// + +/* 宏定义 */ +#define MaxBookNum 1000 // 允许的最大书目数(假设最多只对1000本书建索引表) +#define MaxKeyNum 2500 // 索引表最大容量(索引项数量的最大值) +#define MaxLineLen 500 // 书目串(行)的最大长度 +#define MaxWordNum 100 // 词表的最大容量 + +/* 类型定义 */ + +// 布尔类型 +typedef Status Boolean; + +// 词表类型(顺序表) +typedef struct { + char* item[MaxWordNum]; // 词表集合 + int last; // 词表的长度 +} WordListType; + +// 索引项类型(索引表的行) +typedef struct { + HString key; // 关键词 + ELinkList bnolist; // 存放书号索引的链表 +} IdxTermType; + +/* + * 索引表类型 + * + *【注】 + * 0号单元存储表头信息,这一点与教材有所不同 + */ +typedef struct { + IdxTermType item[MaxKeyNum + 1]; // 索引项的集合 + int last; // 索引表中包含的索引项数目 +} IdxListType; + +/* 全局变量(变量名称前面都加了g标记) */ + +// 书目缓存区 +char gBuf[MaxLineLen]; + +// 关键词词表(普通词表),已经排除了常用词 +WordListType gWdList; + + +/* + * ████████ 算法4.9 ████████ + * + * 从文件bookinfo中读取书目信息,并依此创建相应的关键词索引表,然后将索引表写入文件bookidx。 + */ +void Main(char* bookinfo, char* bookidx); + +/* + * 初始化索引表 + * + *【注】 + * 教材中将索引表表头置为空串,但这里设定了一个有意义的表头 + */ +void InitIdxList(IdxListType* idxlist); + +/* + * 从文件f中读取一条书目信息存入书目缓冲区gBuf。 + */ +void GetLine(FILE* f); + +/* + * 从缓冲区gBuf中提取书名关键词到词表gWdList,书号存入bno。 + */ +void ExtractKeyWord(ElemType* bno); + +/* + * ████████ 算法4.10 ████████ + * + * 将书号bno对应的书名关键词按词典顺序插入到索引表idxlist。 + */ +Status InsIdxList(IdxListType* idxlist, int bno); + +/* + * ████████ 算法4.11 ████████ + * + * 用wd返回词表gWdList中第i个关键词。 + */ +void GetWord(int i, HString* wd); + +/* + * ████████ 算法4.12 ████████ + * + * 查询在索引表idxlist中是否存在与wd相等的关键词。 + * 若存在,则返回wd在词表中的位置,并置b为TRUE。 + * 若不存在,则返回wd应插入的位置,并置b为FALSE。 + */ +int Locate(IdxListType idxlist, HString wd, Boolean* b); + +/* + * ████████ 算法4.13 ████████ + * + * 在索引表的索引i(>=0)处插入关键词wd,并初始化书号索引的链表为空表。 + */ +void InsertNewKey(IdxListType* idxlist, int i, HString wd); + +/* + * ████████ 算法4.14 ████████ + * + * 为索引表在索引i(>0)处的关键词插入书号。 + */ +Status InsertBook(IdxListType* idxlist, int i, int bno); + +/* + * 将生成的索引表idxlist输出到文件g。 + */ +void PutText(FILE* g, IdxListType idxlist); + +// 判断str是否为常用词 +static Status isCommonWords(char* str); + +#endif diff --git a/CLion/CourseBook/CMakeLists.txt b/CLion/CourseBook/CMakeLists.txt index 316461a..eecb2ad 100644 --- a/CLion/CourseBook/CMakeLists.txt +++ b/CLion/CourseBook/CMakeLists.txt @@ -23,3 +23,5 @@ add_subdirectory(0309_BankQueuing) add_subdirectory(0401_SString) add_subdirectory(0402_HString) add_subdirectory(0403_LString) +add_subdirectory(0404_KMP) +add_subdirectory(0405_WordList) diff --git a/Dev-C++/CourseBook/0404_KMP/KMP-main.cpp b/Dev-C++/CourseBook/0404_KMP/KMP-main.cpp new file mode 100644 index 0000000..451bec1 --- /dev/null +++ b/Dev-C++/CourseBook/0404_KMP/KMP-main.cpp @@ -0,0 +1,64 @@ +#include "KMP.h" //**04 **// + +// Ժӡַ +void PrintElem(SString S); + +int main(int argc, char** argv) { + char* s = "abaaabcaabaabcacabaabcaabaabcac"; + char* t = "abaabcac"; + SString S, T; + int* next; // ģʽnextֵ + int* nextval; // ģʽnextvalֵ + int pos; // ƥ + int i, j; + + StrAssign(S, s); // ʼ + printf("S = "); + PrintElem(S); + + StrAssign(T, t); // ʼģʽ + printf("T = "); + PrintElem(T); + + + // עnextnextval0ŵԪõģ1ŵԪʼ洢Ч + next = (int*) malloc((T[0] + 1) * sizeof(int)); + nextval = (int*) malloc((T[0] + 1) * sizeof(int)); + + get_next(T, next); // 㷨4.7 + get_nextval(T, nextval); // 㷨4.8㷨4.7ĸĽ + + printf("next : "); + for(i = 1; i <= T[0]; i++) { + printf("%d", next[i]); + } + printf("\n"); + + printf("nextval : "); + for(i = 1; i <= T[0]; i++) { + printf("%d", nextval[i]); + } + printf("\n"); + + + pos = 1; + + i = Index_KMP(S, T, pos, next); + j = Index_KMP(S, T, pos, nextval); + + printf("%dַT S еһƥɹλΪ %d\n", pos, i); + printf("%dַT S еһƥɹλΪ %d\n", pos, j); + + return 0; +} + +// Ժӡַ +void PrintElem(SString S) { + int i; + + for(i = 1; i <= S[0]; i++) { + printf("%c", S[i]); + } + + printf("\n"); +} diff --git a/Dev-C++/CourseBook/0404_KMP/KMP.cpp b/Dev-C++/CourseBook/0404_KMP/KMP.cpp new file mode 100644 index 0000000..a9daf07 --- /dev/null +++ b/Dev-C++/CourseBook/0404_KMP/KMP.cpp @@ -0,0 +1,106 @@ +/*======================= + * KMP㷨 + * + * 㷨: 4.64.74.8 + ========================*/ + +#include "KMP.h" //**04 **// + +/* + * 㷨4.6 + * + * + * + * posʼģʽTS״γֵλãڣ򷵻0 + * ҳɹƥλá + * + *ע + * 1.ʵõKMP㷨һֱȽϸЧַƥ䷽ʽ + * 2.̲ûnext + */ +int Index_KMP(SString S, SString T, int pos, int next[]) { + int i = pos; + int j = 1; + + if(pos < 1) { + return 0; + } + + // Ƚַ + while(i <= S[0] && j <= T[0]) { + /* + * Σ + * 1.ģʽĵһַʧ + * 2.ģʽַ + */ + if(j == 0 || S[i] == T[j]) { + i++; + j++; + } else { + // ʧʱصǰһʵλ + j = next[j]; + } + } + + if(j > T[0]) { + // ƥɹƥλ + return i - T[0]; + } else { + // ƥʧ + return 0; + } +} + +/* + * 㷨4.7 + * + * ģʽġʧ顱KMP㷨 + */ +void get_next(SString T, int next[]) { + int i = 1; + int j = 0; + + // ģʽһַʧʱģʽҪͷȽϣҪǰһλñȽ + next[1] = 0; + + // ģʽϵַ + while(i < T[0]) { + if(j == 0 || T[i] == T[j]) { + i++; + j++; + next[i] = j; + } else { + j = next[j]; + } + } +} + +/* + * 㷨4.8 + * + * ģʽġʧ顱KMP㷨 + * һŻİ汾Чʽ㷨4.7ߡ + */ +void get_nextval(SString T, int nextval[]) { + int i = 1; + int j = 0; + + // ģʽһַʧʱģʽҪͷȽϣҪǰһλñȽ + nextval[1] = 0; + + // ģʽϵַ + while(i < T[0]) { + if(j==0 || T[i] == T[j]) { + i++; + j++; + + if(T[i] != T[j]) { + nextval[i] = j; + } else { + nextval[i] = nextval[j]; + } + } else { + j = nextval[j]; + } + } +} diff --git a/Dev-C++/CourseBook/0404_KMP/KMP.dev b/Dev-C++/CourseBook/0404_KMP/KMP.dev new file mode 100644 index 0000000..b0c7aa2 --- /dev/null +++ b/Dev-C++/CourseBook/0404_KMP/KMP.dev @@ -0,0 +1,102 @@ +[Project] +FileName=KMP.dev +Name=KMP +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=0 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +CommandLine= +Folders= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=1 +CompilerSettings=0000000000000000001000000 +UnitCount=5 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit3] +FileName=KMP-main.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit1] +FileName=KMP.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=SString.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=KMP.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=SString.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/Dev-C++/CourseBook/0404_KMP/KMP.h b/Dev-C++/CourseBook/0404_KMP/KMP.h new file mode 100644 index 0000000..e479595 --- /dev/null +++ b/Dev-C++/CourseBook/0404_KMP/KMP.h @@ -0,0 +1,43 @@ +/*======================= + * KMP㷨 + * + * 㷨: 4.64.74.8 + ========================*/ + +#ifndef KMP_H +#define KMP_H + +#include +#include +#include "SString.h" //**04 **// + +/* + * 㷨4.6 + * + * + * + * posʼģʽTS״γֵλãڣ򷵻0 + * ҳɹƥλá + * + *ע + * 1.ʵõKMP㷨һֱȽϸЧַƥ䷽ʽ + * 2.̲ûnext + */ +int Index_KMP(SString S, SString T, int pos, int next[]); + +/* + * 㷨4.7 + * + * ģʽġʧ顱KMP㷨 + */ +void get_next(SString T, int next[]); + +/* + * 㷨4.8 + * + * ģʽġʧ顱KMP㷨 + * һŻİ汾Чʽ㷨4.7ߡ + */ +void get_nextval(SString T, int nextval[]); + +#endif diff --git a/Dev-C++/CourseBook/0404_KMP/SString.cpp b/Dev-C++/CourseBook/0404_KMP/SString.cpp new file mode 100644 index 0000000..dc37d0a --- /dev/null +++ b/Dev-C++/CourseBook/0404_KMP/SString.cpp @@ -0,0 +1,33 @@ +/*============================= + * Ķ˳洢ʾ˳򴮣 + * + * 㷨: 4.14.24.34.5 + ==============================*/ + +#include "SString.h" //**04 **// + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(SString T, const char* chars) { + int i, len; + + len = (int) strlen(chars); + + // chars + if(len > MAXSTRLEN) { + return ERROR; + } + + T[0] = len; + for(i = 1; i <= len; i++) { + T[i] = chars[i - 1]; + } + + return OK; +} diff --git a/Dev-C++/CourseBook/0404_KMP/SString.h b/Dev-C++/CourseBook/0404_KMP/SString.h new file mode 100644 index 0000000..bf6ac73 --- /dev/null +++ b/Dev-C++/CourseBook/0404_KMP/SString.h @@ -0,0 +1,36 @@ +/*============================= + * Ķ˳洢ʾ˳򴮣 + * + * 㷨: 4.14.24.34.5 + ==============================*/ + +#ifndef SSTRING_H +#define SSTRING_H + +#include +#include // ṩstrlenԭ +#include "Status.h" //**01 **// + +/* 궨 */ +#define MAXSTRLEN 255 // ˳򴮵󴮳 + +/* + * ˳洢Ͷ + * + * עЧԪشSString1ŵԪʼ洢 + * SString0ŵԪ洢䳤 + */ +typedef unsigned char SString[MAXSTRLEN + 1]; // 0ŵԪŴij + + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(SString T, const char* chars); + +#endif diff --git a/Dev-C++/CourseBook/0405_WordList/ELinkList.cpp b/Dev-C++/CourseBook/0405_WordList/ELinkList.cpp new file mode 100644 index 0000000..2307476 --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/ELinkList.cpp @@ -0,0 +1,95 @@ +/*======================= + * չĵ + * + * 㷨: 2.20 + ========================*/ + +#include "ELinkList.h" //**02 Ա**// + + +/* ڴ */ + +/* + * ڴ + * + * Ϊһ㣬ָe + * + *ע + * staticεĺǸú޵ǰļʹ + */ +Status MakeNode(Link* p, ElemType e) { + if(p == NULL) { + return ERROR; + } + + // ռ + *p = (Link) malloc(sizeof(LNode)); + if(*p == NULL) { + // û˳򣬶Ƿشʾ + return ERROR; + } + + (*p)->data = e; + (*p)->next = NULL; + + return OK; +} + + +/* */ + +/* + * ʼ + * + * ʼɹ򷵻OK򷵻ERROR + */ +Status InitList(ELinkList* L) { + Link p; + + if(L == NULL) { + return ERROR; + } + + // ͷ + p = (Link) malloc(sizeof(LNode)); + if(p == NULL) { + exit(OVERFLOW); + } + p->next = NULL; + + // ֻͷʱλαָ + (*L).head = (*L).tail = p; + (*L).len = 0; + + return OK; +} + + +/* չ */ + +/* + * β + * + * sָһL + */ +Status Append(ELinkList* L, Link s) { + int count; + + if(L == NULL || (*L).head == NULL || s == NULL) { + return ERROR; + } + + count = 0; + (*L).tail->next = s; + + // ȷµβλ + while(s != NULL) { + (*L).tail = s; + s = s->next; + count++; + } + + (*L).len += count; + + return OK; +} diff --git a/Dev-C++/CourseBook/0405_WordList/ELinkList.h b/Dev-C++/CourseBook/0405_WordList/ELinkList.h new file mode 100644 index 0000000..72ce3b0 --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/ELinkList.h @@ -0,0 +1,75 @@ +/*======================= + * չĵ + * + * 㷨: 2.20 + ========================*/ + +#ifndef ELINKLIST_H +#define ELINKLIST_H + +#include +#include // ṩmallocreallocfreeexitԭ +#include // ṩһЩ޳ +#include "Status.h" //**01 **// + +/* + * ע + * + * ̲еΪLinkList + * Ϊ뵥֣ʽΪELinkList + * ɶͨһչ + */ + +/* ԪͶ */ +typedef int ElemType; + +/* + * ṹ + * + * עͷ + */ +typedef struct LNode { + ElemType data; + struct LNode* next; +} LNode, * Link, * Position; + +/* άͷβָ뼰Ϣ */ +typedef struct { + Link head, tail; // ֱָеͷβ + int len; // ָʾԪصĸ +} ELinkList; + + +/* ڴ */ + +/* + * ڴ + * + * Ϊһ㣬ָe + * + *ע + * staticεĺǸú޵ǰļʹ + */ +Status MakeNode(Link* p, ElemType e); + + +/* */ + +/* + * ʼ + * + * ʼɹ򷵻OK򷵻ERROR + */ +Status InitList(ELinkList* L); + + +/* չ */ + +/* + * β + * + * sָһL + */ +Status Append(ELinkList* L, Link s); + +#endif diff --git a/Dev-C++/CourseBook/0405_WordList/HString.cpp b/Dev-C++/CourseBook/0405_WordList/HString.cpp new file mode 100644 index 0000000..8d1fc00 --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/HString.cpp @@ -0,0 +1,95 @@ +/*========================= + * Ķѷ洢ʾѴ + * + * 㷨: 4.4 + ==========================*/ + +#include "HString.h" //**04 **// + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(HString* T, const char* chars) { + int i, j; + + // charsij + i = (int) strlen(chars); + + // ûЧԪ + if(i == 0) { + (*T).ch = NULL; + (*T).length = 0; + + return OK; + } + + // ЧԪʱҪ洢ռ + (*T).ch = (char*) malloc(i * sizeof(char)); + if(!((*T).ch)) { + exit(OVERFLOW); + } + + for(j = 0; j < i; j++) { + (*T).ch[j] = chars[j]; + } + + (*T).length = i; + + return OK; +} + +/* + * Ƚ + * + * ȽϴSʹTرȽϽ + * + *ע + * òСӼ + */ +Status StrCompare(HString S, HString T) { + int i; + + for(i = 0; i < S.length && i < T.length; i++) { + // ַͬʱȽС + if(S.ch[i] != T.ch[i]) { + return S.ch[i] - T.ch[i]; + } + } + + return S.length - T.length; +} + +/* + * + * + * SƵT + */ +Status StrCopy(HString* T, HString S) { + int i; + + if(S.length == 0) { + (*T).ch = NULL; + (*T).length = 0; + } else { + // ռ + (*T).ch = (char*) malloc(S.length * sizeof(char)); + if(!(*T).ch) { + exit(OVERFLOW); + } + + // Ԫ + for(i = 0; i < S.length; i++) { + (*T).ch[i] = S.ch[i]; + } + + // ƳϢ + (*T).length = S.length; + } + + return OK; +} diff --git a/Dev-C++/CourseBook/0405_WordList/HString.h b/Dev-C++/CourseBook/0405_WordList/HString.h new file mode 100644 index 0000000..3ab0a9e --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/HString.h @@ -0,0 +1,53 @@ +/*========================= + * Ķѷ洢ʾѴ + * + * 㷨: 4.4 + ==========================*/ + +#ifndef HSTRING +#define HSTRING + +#include +#include // ṩmallocreallocfreeexitԭ +#include // ṩstrlenԭ +#include "Status.h" //**01 **// + +/* + * ĶѴ洢ʾ + * + * עЧԪشch0ŵԪʼ洢 + */ +typedef struct { + char* ch; // Ƿǿմ򰴴洢chΪNULL + int length; +} HString; + + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(HString* T, const char* chars); + +/* + * Ƚ + * + * ȽϴSʹTرȽϽ + * + *ע + * òСӼ + */ +Status StrCompare(HString S, HString T); + +/* + * + * + * SƵT + */ +Status StrCopy(HString* T, HString S); + +#endif diff --git a/Dev-C++/CourseBook/0405_WordList/TestData.txt b/Dev-C++/CourseBook/0405_WordList/TestData.txt new file mode 100644 index 0000000..9b3437f --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/TestData.txt @@ -0,0 +1,7 @@ + + 005 Computer Data Structures + 010 Introduction to Data Structures + 023 Fundamentals of Data Structures + 034 The Design and Analysis of Computer Algorithms + 050 Introduction to Numerical Analysis + 067 Numerical Analysis diff --git a/Dev-C++/CourseBook/0405_WordList/WordList-main.cpp b/Dev-C++/CourseBook/0405_WordList/WordList-main.cpp new file mode 100644 index 0000000..70fb3b3 --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/WordList-main.cpp @@ -0,0 +1,27 @@ +#include // ṩsystemԭ +#include "WordList.h" //**04 **// + +int main(int argc, char** argv) { + FILE* fp; + char line[MaxLineLen]; + + char* bookinfo = "TestData.txt"; // Ŀļ + char* bookidx = "BookIdx.txt"; // ؼļ + + // + Main(bookinfo, bookidx); + + // ʾĻ + if((fp = fopen(bookidx, "r"))!=NULL) { + printf("---------ɹ---------\n\n"); + + while(feof(fp)==FALSE) { + fgets(line, MaxLineLen, fp); + printf("%s", line); + } + } else { + printf("---------δ---------\n"); + } + + return 0; +} diff --git a/Dev-C++/CourseBook/0405_WordList/WordList.cpp b/Dev-C++/CourseBook/0405_WordList/WordList.cpp new file mode 100644 index 0000000..a22baf1 --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/WordList.cpp @@ -0,0 +1,308 @@ +/*=========================================== + * + * + * 㷨: 4.94.104.114.124.134.14 + ============================================*/ + +#include "WordList.h" //**04 **// + +/* + * 㷨4.9 + * + * ļbookinfoжȡĿϢ˴ӦĹؼȻдļbookidx + */ +void Main(char* bookinfo, char* bookidx) { + FILE* f, * g; + char head[MaxLineLen]; // ĿıͷϢδʹã + IdxListType idxlist; // ؼ + ElemType bno; // + int count; + + // ԡֻģʽĿļ + if((f = fopen(bookinfo, "r")) != NULL) { + + // ԡֻдģʽļ + if((g = fopen(bookidx, "w")) != NULL) { + + // ʼ + InitIdxList(&idxlist); + + // ļһ + fgets(head, MaxLineLen, f); + + count = 0; + + // δļβһֱļ + while(feof(f) == FALSE && count < MaxBookNum) { + + // ļfһĿϢĿgBuf + GetLine(f); + + // gBufȡؼʵʱgWdListŴbno + ExtractKeyWord(&bno); + + // żӦĹؼʲidxlist + InsIdxList(&idxlist, bno); + + count++; + } + + // ļgд + PutText(g, idxlist); + + fclose(g); + } + + fclose(f); + } +} + +/* + * ʼ + * + *ע + * ̲нͷΪմ趨һıͷ + */ +void InitIdxList(IdxListType* idxlist) { + // ıͷϢ + char* chars = "ؼ "; + IdxTermType e; + + // ʼͷϢ + StrAssign(&(e.key), chars); + + // ʼ + InitList(&(e.bnolist)); + + (*idxlist).item[0] = e; + + // ͷΪ0Ϣ + (*idxlist).last = 0; +} + +/* + * ļfжȡһĿϢĿgBuf + */ +void GetLine(FILE* f) { + // ȡһݣ뻺gBuf + fgets(gBuf, MaxLineLen, f); +} + +/* + * ӻgBufȡؼʵʱgWdListŴbno + */ +void ExtractKeyWord(ElemType* bno) { + char delim[] = {'-', ' ', '\r', '\n', '\t'}; // ָ + char* title; // + char* token; // зֽĹؼ + + // ֽĿַŴbno(ʮ)titleָʣµַ() + *bno = (int) strtol(gBuf, &title, 10); + + // ɴдСд + strlwr(title); + + // չؼʴʱ + gWdList.last = 0; + + // ֽؼ + for(token = strtok(title, delim); token != NULL; token = strtok(NULL, delim)) { + // ùؼdzôʣ + if(isCommonWords(token) == TRUE) { + continue; + } + + // ´ȡĹؼ + gWdList.item[gWdList.last++] = token; + } +} + +/* + * 㷨4.10 + * + * bnoӦеĹؼʰʵ˳뵽idxlist + */ +Status InsIdxList(IdxListType* idxlist, int bno) { + int i, j; + Boolean boo; + HString wd; + + if(gWdList.last <= 0) { + return ERROR; + } + + // bnoӦейؼ + for(i = 0; i < gWdList.last; i++) { + // ȡĹؼ + GetWord(i, &wd); + + // жϸùؼǷѾλ + j = Locate(*idxlist, wd, &boo); + + // ùؼʲУҪؼ + if(boo == FALSE) { + // ؼwd뵽 + InsertNewKey(idxlist, j, wd); + } + + // ڹؼѴڵ£ + if(!InsertBook(idxlist, j, bno)) { + return ERROR; + } + } + + return OK; +} + +/* + * 㷨4.11 + * + * wdشʱgWdListеiؼʡ + */ +void GetWord(int i, HString* wd) { + if(i < 0 || i > gWdList.last - 1) { + StrAssign(wd, ""); + } else { + StrAssign(wd, gWdList.item[i]); + } +} + +/* + * 㷨4.12 + * + * ѯidxlistǷwdȵĹؼʡ + * ڣ򷵻wdڴʱеλãbΪTRUE + * ڣ򷵻wdӦλãbΪFALSE + */ +int Locate(IdxListType idxlist, HString wd, Boolean* b) { + int i, m = -1; + + /* + * idxlistвҹؼwdǷ + * ע0ŵԪ洢˱ͷϢ + */ + for(i = idxlist.last; i > 0 && (m = StrCompare(idxlist.item[i].key, wd)) > 0; i--) { + } + + // ҵ˹ؼwd + if(m == 0) { + *b = TRUE; + return i; + } else { + *b = FALSE; + return i + 1; + } +} + +/* + * 㷨4.13 + * + * i(>=0)ؼwdʼΪձ + */ +void InsertNewKey(IdxListType* idxlist, int i, HString wd) { + int j; + + /* + * + * ע0ŵԪ洢˱ͷϢ + */ + for(j = (*idxlist).last; j >= i; j--) { + (*idxlist).item[j + 1] = (*idxlist).item[j]; + } + + // + StrCopy(&((*idxlist).item[i].key), wd); + + // ʼ + InitList(&((*idxlist).item[i].bnolist)); + + // Ŀһ + (*idxlist).last++; +} + +/* + * 㷨4.14 + * + * Ϊi(>0)Ĺؼʲš + */ +Status InsertBook(IdxListType* idxlist, int i, ElemType bno) { + Link p; + + // ڴʧ + if(MakeNode(&p, bno) == FALSE) { + return ERROR; + } + + // µ + Append(&((*idxlist).item[i].bnolist), p); + + return OK; +} + +/* + * ɵidxlistļg + */ +void PutText(FILE* g, IdxListType idxlist) { + int i, j, m, n; + Link p; + HString S; + ELinkList L; + + if(idxlist.last <= 0) { + return; + } + + // ͷϢ + S = idxlist.item[0].key; + for(m = 0; m < S.length; m++) { + fprintf(g, "%c", S.ch[m]); + } + fprintf(g, "\n"); + + // Ϣ + for(i = 1; i <= idxlist.last; i++) { + // 1.ؼ + S = idxlist.item[i].key; + for(m = 0; m < S.length; m++) { + fprintf(g, "%c", S.ch[m]); + } + + // 2.ո + for(j = 1; j <= 18 - idxlist.item[i].key.length; j++) { + fprintf(g, " "); + } + + // 3. + L = idxlist.item[i].bnolist; + for(n = 1, p = L.head->next; n <= L.len; n++) { + fprintf(g, "%03d", p->data); + p = p->next; + if(p) { + fprintf(g, ""); + } + } + + // 4. + fprintf(g, "\n"); + } + +} + +// жstrǷΪô +static Status isCommonWords(char* str) { + int i; + + // ôʴʱЩʻᱻųڹؼ֮ + WordListType words = {{"a", "an", "the", "of", "and", "is", "to", "as", "in", "for"}, 10}; + + // ѯôʴʱ + for(i = 0; i < words.last; i++) { + // ַкԴСдıȽ + if(strcmpi(str, words.item[i]) == 0) { + // ַdzôʣ򷵻TRUE + return TRUE; + } + } + + return FALSE; +} diff --git a/Dev-C++/CourseBook/0405_WordList/WordList.dev b/Dev-C++/CourseBook/0405_WordList/WordList.dev new file mode 100644 index 0000000..b6e6a55 --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/WordList.dev @@ -0,0 +1,131 @@ +[Project] +FileName=WordList.dev +Name=WordList +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=0 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +CommandLine= +Folders= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=1 +CompilerSettings=0000000000000000001000000 +UnitCount=8 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit7] +FileName=WordList-main.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit1] +FileName=ELinkList.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=HString.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=WordList.cpp +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=ELinkList.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=HString.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=WordList.h +CompileCpp=0 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=TestData.txt +Folder= +Compile=0 +Link=0 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/Dev-C++/CourseBook/0405_WordList/WordList.h b/Dev-C++/CourseBook/0405_WordList/WordList.h new file mode 100644 index 0000000..1b9af7b --- /dev/null +++ b/Dev-C++/CourseBook/0405_WordList/WordList.h @@ -0,0 +1,130 @@ +/*=========================================== + * + * + * 㷨: 4.94.104.114.124.134.14 + ============================================*/ + +#ifndef WORDLIST_H +#define WORDLIST_H + +#include // ṩfopenfclosefeoffgetsԭ +#include // ṩexitstrtolԭ +#include // ṩstrlenstrcmpistrlwrԭ +#include "Status.h" //**01 **// +#include "ELinkList.h" //**02 Ա**// +#include "HString.h" //**04 **// + +/* 궨 */ +#define MaxBookNum 1000 // Ŀֻ1000齨 +#define MaxKeyNum 2500 // (ֵ) +#define MaxLineLen 500 // Ŀ()󳤶 +#define MaxWordNum 100 // ʱ + +/* Ͷ */ + +// +typedef Status Boolean; + +// ʱ(˳) +typedef struct { + char* item[MaxWordNum]; // ʱ + int last; // ʱij +} WordListType; + +// ͣУ +typedef struct { + HString key; // ؼ + ELinkList bnolist; // +} IdxTermType; + +/* + * + * + *ע + * 0ŵԪ洢ͷϢһ̲ͬ + */ +typedef struct { + IdxTermType item[MaxKeyNum + 1]; // ļ + int last; // аĿ +} IdxListType; + +/* ȫֱǰ涼gǣ */ + +// Ŀ +static char gBuf[MaxLineLen]; + +// ؼʴʱ(ͨʱ)Ѿų˳ô +static WordListType gWdList; + + +/* + * 㷨4.9 + * + * ļbookinfoжȡĿϢ˴ӦĹؼȻдļbookidx + */ +void Main(char* bookinfo, char* bookidx); + +/* + * ʼ + * + *ע + * ̲нͷΪմ趨һıͷ + */ +void InitIdxList(IdxListType* idxlist); + +/* + * ļfжȡһĿϢĿgBuf + */ +void GetLine(FILE* f); + +/* + * ӻgBufȡؼʵʱgWdListŴbno + */ +void ExtractKeyWord(ElemType* bno); + +/* + * 㷨4.10 + * + * bnoӦؼʰʵ˳뵽idxlist + */ +Status InsIdxList(IdxListType* idxlist, int bno); + +/* + * 㷨4.11 + * + * wdشʱgWdListеiؼʡ + */ +void GetWord(int i, HString* wd); + +/* + * 㷨4.12 + * + * ѯidxlistǷwdȵĹؼʡ + * ڣ򷵻wdڴʱеλãbΪTRUE + * ڣ򷵻wdӦλãbΪFALSE + */ +int Locate(IdxListType idxlist, HString wd, Boolean* b); + +/* + * 㷨4.13 + * + * i(>=0)ؼwdʼΪձ + */ +void InsertNewKey(IdxListType* idxlist, int i, HString wd); + +/* + * 㷨4.14 + * + * Ϊi(>0)Ĺؼʲš + */ +Status InsertBook(IdxListType* idxlist, int i, int bno); + +/* + * ɵidxlistļg + */ +void PutText(FILE* g, IdxListType idxlist); + +// жstrǷΪô +static Status isCommonWords(char* str); + +#endif diff --git a/README.md b/README.md index 600f1d1..f15bc10 100644 --- a/README.md +++ b/README.md @@ -91,29 +91,31 @@ Commit信息中的`emoji`参考来源: ## 附:教材源码目录 -| 章 | 节 | 内容 | 包含算法 | 备注 | -| :--------- | :---------- | :----------- | :-------------------- | :------------------- | -| 01 绪论 | Status | | | 定义一些共享常量和函数 | -| 02 线性表 | SqList | 顺序表 | 2.3、2.4、2.5、2.6 | 线性表的顺序存储结构 | -| | Union | A=A∪B | 2.1 | | -| | MergeSqList | C=A+B | 2.2、2.7 | 归并顺序表 | -| | LinkList | 链表 | 2.8、2.9、2.10、2.11 | 线性表的链式存储结构 | -| | MergeList | C=A+B | 2.12 | 归并链表 | -| | SLinkList | 静态链表 | 2.13、2.14、2.15、2.16 | | -| | Difference | (A-B)∪(B-A) | 2.17 | | -| | DuLinkList | 双向循环链表 | 2.18、2.19 | | -| | ELinkList | 扩展的线性链表 | 2.20 | | -| | MergeEList | C=A+B | 2.21 | 归并扩展的线性链表 | -| | Polynomial | 一元多项式 | 2.22、2.23 | | -| 03 栈和队列 | SqStack | 栈 | | 顺序存储结构 | -| | Conversion | 进制转换 | 3.1 | 栈的应用 | -| | LineEdit | 行编辑程序 | 3.2 | 栈的应用 | -| | Maze | 迷宫寻路 | 3.3 | 栈的应用 | -| | Expression | 表达式求值 | 3.4 | 栈的应用 | -| | Hanoi | 汉诺塔 | 3.5 | 递归 | -| | LinkQueue | 链列 | | 链式存储结构 | -| | SqQueue | 顺序队列 | | 循环队列,顺序存储结构 | -| | BankQueuing | 模拟银行排队 | 3.6、3.7 | 队列的应用 | -| 04 串 | SString | 顺序串 | 4.1、4.2、4.3、4.5 | 顺序存储 | -| | HString | 堆串 | 4.4 | 顺序存储,动态分配内存 | -| | LString | 块链串 | | 顺序存储+链式存储 | +| 章 | 节 | 内容 | 包含算法 | 备注 | +| :--------- | :---------- | :----------- | :------------------------------- | :------------------- | +| 01 绪论 | Status | | | 定义一些共享常量和函数 | +| 02 线性表 | SqList | 顺序表 | 2.3、2.4、2.5、2.6 | 线性表的顺序存储结构 | +| | Union | A=A∪B | 2.1 | | +| | MergeSqList | C=A+B | 2.2、2.7 | 归并顺序表 | +| | LinkList | 链表 | 2.8、2.9、2.10、2.11 | 线性表的链式存储结构 | +| | MergeList | C=A+B | 2.12 | 归并链表 | +| | SLinkList | 静态链表 | 2.13、2.14、2.15、2.16 | | +| | Difference | (A-B)∪(B-A) | 2.17 | | +| | DuLinkList | 双向循环链表 | 2.18、2.19 | | +| | ELinkList | 扩展的线性链表 | 2.20 | | +| | MergeEList | C=A+B | 2.21 | 归并扩展的线性链表 | +| | Polynomial | 一元多项式 | 2.22、2.23 | | +| 03 栈和队列 | SqStack | 栈 | | 顺序存储结构 | +| | Conversion | 进制转换 | 3.1 | 栈的应用 | +| | LineEdit | 行编辑程序 | 3.2 | 栈的应用 | +| | Maze | 迷宫寻路 | 3.3 | 栈的应用 | +| | Expression | 表达式求值 | 3.4 | 栈的应用 | +| | Hanoi | 汉诺塔 | 3.5 | 递归 | +| | LinkQueue | 链列 | | 链式存储结构 | +| | SqQueue | 顺序队列 | | 循环队列,顺序存储结构 | +| | BankQueuing | 模拟银行排队 | 3.6、3.7 | 队列的应用 | +| 04 串 | SString | 顺序串 | 4.1、4.2、4.3、4.5 | 顺序存储 | +| | HString | 堆串 | 4.4 | 顺序存储,动态分配内存 | +| | LString | 块链串 | | 顺序存储+链式存储 | +| | KMP | KMP算法 | 4.6、4.7、4.8 | 字符串匹配算法 | +| | WordList | 关键词索引 | 4.9、4.10、4.11、4.12、4.13、4.14 | 堆串和线性表的应用 | diff --git a/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj b/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj new file mode 100644 index 0000000..af34b7b --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj @@ -0,0 +1,78 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {5D2A1F0B-F177-43A9-873A-56C7E08E6987} + My0404_KMP + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + $(SolutionDir)\..\Status;$(IncludePath) + + + + Level3 + Disabled + + + true + Console + $(SolutionDir)\..\Status\Status.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj.filters b/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj.filters new file mode 100644 index 0000000..aef50b8 --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 头文件 + + + 头文件 + + + + + 源文件 + + + 源文件 + + + 源文件 + + + \ No newline at end of file diff --git a/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj.user b/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/0404_KMP.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/VisualC++/CourseBook/0404_KMP/KMP-main.c b/VisualC++/CourseBook/0404_KMP/KMP-main.c new file mode 100644 index 0000000..451bec1 --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/KMP-main.c @@ -0,0 +1,64 @@ +#include "KMP.h" //**04 **// + +// Ժӡַ +void PrintElem(SString S); + +int main(int argc, char** argv) { + char* s = "abaaabcaabaabcacabaabcaabaabcac"; + char* t = "abaabcac"; + SString S, T; + int* next; // ģʽnextֵ + int* nextval; // ģʽnextvalֵ + int pos; // ƥ + int i, j; + + StrAssign(S, s); // ʼ + printf("S = "); + PrintElem(S); + + StrAssign(T, t); // ʼģʽ + printf("T = "); + PrintElem(T); + + + // עnextnextval0ŵԪõģ1ŵԪʼ洢Ч + next = (int*) malloc((T[0] + 1) * sizeof(int)); + nextval = (int*) malloc((T[0] + 1) * sizeof(int)); + + get_next(T, next); // 㷨4.7 + get_nextval(T, nextval); // 㷨4.8㷨4.7ĸĽ + + printf("next : "); + for(i = 1; i <= T[0]; i++) { + printf("%d", next[i]); + } + printf("\n"); + + printf("nextval : "); + for(i = 1; i <= T[0]; i++) { + printf("%d", nextval[i]); + } + printf("\n"); + + + pos = 1; + + i = Index_KMP(S, T, pos, next); + j = Index_KMP(S, T, pos, nextval); + + printf("%dַT S еһƥɹλΪ %d\n", pos, i); + printf("%dַT S еһƥɹλΪ %d\n", pos, j); + + return 0; +} + +// Ժӡַ +void PrintElem(SString S) { + int i; + + for(i = 1; i <= S[0]; i++) { + printf("%c", S[i]); + } + + printf("\n"); +} diff --git a/VisualC++/CourseBook/0404_KMP/KMP.c b/VisualC++/CourseBook/0404_KMP/KMP.c new file mode 100644 index 0000000..a9daf07 --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/KMP.c @@ -0,0 +1,106 @@ +/*======================= + * KMP㷨 + * + * 㷨: 4.64.74.8 + ========================*/ + +#include "KMP.h" //**04 **// + +/* + * 㷨4.6 + * + * + * + * posʼģʽTS״γֵλãڣ򷵻0 + * ҳɹƥλá + * + *ע + * 1.ʵõKMP㷨һֱȽϸЧַƥ䷽ʽ + * 2.̲ûnext + */ +int Index_KMP(SString S, SString T, int pos, int next[]) { + int i = pos; + int j = 1; + + if(pos < 1) { + return 0; + } + + // Ƚַ + while(i <= S[0] && j <= T[0]) { + /* + * Σ + * 1.ģʽĵһַʧ + * 2.ģʽַ + */ + if(j == 0 || S[i] == T[j]) { + i++; + j++; + } else { + // ʧʱصǰһʵλ + j = next[j]; + } + } + + if(j > T[0]) { + // ƥɹƥλ + return i - T[0]; + } else { + // ƥʧ + return 0; + } +} + +/* + * 㷨4.7 + * + * ģʽġʧ顱KMP㷨 + */ +void get_next(SString T, int next[]) { + int i = 1; + int j = 0; + + // ģʽһַʧʱģʽҪͷȽϣҪǰһλñȽ + next[1] = 0; + + // ģʽϵַ + while(i < T[0]) { + if(j == 0 || T[i] == T[j]) { + i++; + j++; + next[i] = j; + } else { + j = next[j]; + } + } +} + +/* + * 㷨4.8 + * + * ģʽġʧ顱KMP㷨 + * һŻİ汾Чʽ㷨4.7ߡ + */ +void get_nextval(SString T, int nextval[]) { + int i = 1; + int j = 0; + + // ģʽһַʧʱģʽҪͷȽϣҪǰһλñȽ + nextval[1] = 0; + + // ģʽϵַ + while(i < T[0]) { + if(j==0 || T[i] == T[j]) { + i++; + j++; + + if(T[i] != T[j]) { + nextval[i] = j; + } else { + nextval[i] = nextval[j]; + } + } else { + j = nextval[j]; + } + } +} diff --git a/VisualC++/CourseBook/0404_KMP/KMP.h b/VisualC++/CourseBook/0404_KMP/KMP.h new file mode 100644 index 0000000..e479595 --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/KMP.h @@ -0,0 +1,43 @@ +/*======================= + * KMP㷨 + * + * 㷨: 4.64.74.8 + ========================*/ + +#ifndef KMP_H +#define KMP_H + +#include +#include +#include "SString.h" //**04 **// + +/* + * 㷨4.6 + * + * + * + * posʼģʽTS״γֵλãڣ򷵻0 + * ҳɹƥλá + * + *ע + * 1.ʵõKMP㷨һֱȽϸЧַƥ䷽ʽ + * 2.̲ûnext + */ +int Index_KMP(SString S, SString T, int pos, int next[]); + +/* + * 㷨4.7 + * + * ģʽġʧ顱KMP㷨 + */ +void get_next(SString T, int next[]); + +/* + * 㷨4.8 + * + * ģʽġʧ顱KMP㷨 + * һŻİ汾Чʽ㷨4.7ߡ + */ +void get_nextval(SString T, int nextval[]); + +#endif diff --git a/VisualC++/CourseBook/0404_KMP/SString.c b/VisualC++/CourseBook/0404_KMP/SString.c new file mode 100644 index 0000000..dc37d0a --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/SString.c @@ -0,0 +1,33 @@ +/*============================= + * Ķ˳洢ʾ˳򴮣 + * + * 㷨: 4.14.24.34.5 + ==============================*/ + +#include "SString.h" //**04 **// + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(SString T, const char* chars) { + int i, len; + + len = (int) strlen(chars); + + // chars + if(len > MAXSTRLEN) { + return ERROR; + } + + T[0] = len; + for(i = 1; i <= len; i++) { + T[i] = chars[i - 1]; + } + + return OK; +} diff --git a/VisualC++/CourseBook/0404_KMP/SString.h b/VisualC++/CourseBook/0404_KMP/SString.h new file mode 100644 index 0000000..bf6ac73 --- /dev/null +++ b/VisualC++/CourseBook/0404_KMP/SString.h @@ -0,0 +1,36 @@ +/*============================= + * Ķ˳洢ʾ˳򴮣 + * + * 㷨: 4.14.24.34.5 + ==============================*/ + +#ifndef SSTRING_H +#define SSTRING_H + +#include +#include // ṩstrlenԭ +#include "Status.h" //**01 **// + +/* 궨 */ +#define MAXSTRLEN 255 // ˳򴮵󴮳 + +/* + * ˳洢Ͷ + * + * עЧԪشSString1ŵԪʼ洢 + * SString0ŵԪ洢䳤 + */ +typedef unsigned char SString[MAXSTRLEN + 1]; // 0ŵԪŴij + + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(SString T, const char* chars); + +#endif diff --git a/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj b/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj new file mode 100644 index 0000000..4ef9c65 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj @@ -0,0 +1,83 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {FA2740D7-2D96-4F57-AE79-FCDA5C13CA86} + My0405_WordList + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + $(SolutionDir)\..\Status;$(IncludePath) + + + + Level3 + Disabled + + + true + Console + $(SolutionDir)\..\Status\Status.lib;%(AdditionalDependencies) + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj.filters b/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj.filters new file mode 100644 index 0000000..9072ae0 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj.filters @@ -0,0 +1,47 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + 源文件 + + + 源文件 + + + 源文件 + + + + + 头文件 + + + 头文件 + + + 头文件 + + + + + 资源文件 + + + \ No newline at end of file diff --git a/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj.user b/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/0405_WordList.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/VisualC++/CourseBook/0405_WordList/ELinkList.c b/VisualC++/CourseBook/0405_WordList/ELinkList.c new file mode 100644 index 0000000..2307476 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/ELinkList.c @@ -0,0 +1,95 @@ +/*======================= + * չĵ + * + * 㷨: 2.20 + ========================*/ + +#include "ELinkList.h" //**02 Ա**// + + +/* ڴ */ + +/* + * ڴ + * + * Ϊһ㣬ָe + * + *ע + * staticεĺǸú޵ǰļʹ + */ +Status MakeNode(Link* p, ElemType e) { + if(p == NULL) { + return ERROR; + } + + // ռ + *p = (Link) malloc(sizeof(LNode)); + if(*p == NULL) { + // û˳򣬶Ƿشʾ + return ERROR; + } + + (*p)->data = e; + (*p)->next = NULL; + + return OK; +} + + +/* */ + +/* + * ʼ + * + * ʼɹ򷵻OK򷵻ERROR + */ +Status InitList(ELinkList* L) { + Link p; + + if(L == NULL) { + return ERROR; + } + + // ͷ + p = (Link) malloc(sizeof(LNode)); + if(p == NULL) { + exit(OVERFLOW); + } + p->next = NULL; + + // ֻͷʱλαָ + (*L).head = (*L).tail = p; + (*L).len = 0; + + return OK; +} + + +/* չ */ + +/* + * β + * + * sָһL + */ +Status Append(ELinkList* L, Link s) { + int count; + + if(L == NULL || (*L).head == NULL || s == NULL) { + return ERROR; + } + + count = 0; + (*L).tail->next = s; + + // ȷµβλ + while(s != NULL) { + (*L).tail = s; + s = s->next; + count++; + } + + (*L).len += count; + + return OK; +} diff --git a/VisualC++/CourseBook/0405_WordList/ELinkList.h b/VisualC++/CourseBook/0405_WordList/ELinkList.h new file mode 100644 index 0000000..72ce3b0 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/ELinkList.h @@ -0,0 +1,75 @@ +/*======================= + * չĵ + * + * 㷨: 2.20 + ========================*/ + +#ifndef ELINKLIST_H +#define ELINKLIST_H + +#include +#include // ṩmallocreallocfreeexitԭ +#include // ṩһЩ޳ +#include "Status.h" //**01 **// + +/* + * ע + * + * ̲еΪLinkList + * Ϊ뵥֣ʽΪELinkList + * ɶͨһչ + */ + +/* ԪͶ */ +typedef int ElemType; + +/* + * ṹ + * + * עͷ + */ +typedef struct LNode { + ElemType data; + struct LNode* next; +} LNode, * Link, * Position; + +/* άͷβָ뼰Ϣ */ +typedef struct { + Link head, tail; // ֱָеͷβ + int len; // ָʾԪصĸ +} ELinkList; + + +/* ڴ */ + +/* + * ڴ + * + * Ϊһ㣬ָe + * + *ע + * staticεĺǸú޵ǰļʹ + */ +Status MakeNode(Link* p, ElemType e); + + +/* */ + +/* + * ʼ + * + * ʼɹ򷵻OK򷵻ERROR + */ +Status InitList(ELinkList* L); + + +/* չ */ + +/* + * β + * + * sָһL + */ +Status Append(ELinkList* L, Link s); + +#endif diff --git a/VisualC++/CourseBook/0405_WordList/HString.c b/VisualC++/CourseBook/0405_WordList/HString.c new file mode 100644 index 0000000..8d1fc00 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/HString.c @@ -0,0 +1,95 @@ +/*========================= + * Ķѷ洢ʾѴ + * + * 㷨: 4.4 + ==========================*/ + +#include "HString.h" //**04 **// + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(HString* T, const char* chars) { + int i, j; + + // charsij + i = (int) strlen(chars); + + // ûЧԪ + if(i == 0) { + (*T).ch = NULL; + (*T).length = 0; + + return OK; + } + + // ЧԪʱҪ洢ռ + (*T).ch = (char*) malloc(i * sizeof(char)); + if(!((*T).ch)) { + exit(OVERFLOW); + } + + for(j = 0; j < i; j++) { + (*T).ch[j] = chars[j]; + } + + (*T).length = i; + + return OK; +} + +/* + * Ƚ + * + * ȽϴSʹTرȽϽ + * + *ע + * òСӼ + */ +Status StrCompare(HString S, HString T) { + int i; + + for(i = 0; i < S.length && i < T.length; i++) { + // ַͬʱȽС + if(S.ch[i] != T.ch[i]) { + return S.ch[i] - T.ch[i]; + } + } + + return S.length - T.length; +} + +/* + * + * + * SƵT + */ +Status StrCopy(HString* T, HString S) { + int i; + + if(S.length == 0) { + (*T).ch = NULL; + (*T).length = 0; + } else { + // ռ + (*T).ch = (char*) malloc(S.length * sizeof(char)); + if(!(*T).ch) { + exit(OVERFLOW); + } + + // Ԫ + for(i = 0; i < S.length; i++) { + (*T).ch[i] = S.ch[i]; + } + + // ƳϢ + (*T).length = S.length; + } + + return OK; +} diff --git a/VisualC++/CourseBook/0405_WordList/HString.h b/VisualC++/CourseBook/0405_WordList/HString.h new file mode 100644 index 0000000..3ab0a9e --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/HString.h @@ -0,0 +1,53 @@ +/*========================= + * Ķѷ洢ʾѴ + * + * 㷨: 4.4 + ==========================*/ + +#ifndef HSTRING +#define HSTRING + +#include +#include // ṩmallocreallocfreeexitԭ +#include // ṩstrlenԭ +#include "Status.h" //**01 **// + +/* + * ĶѴ洢ʾ + * + * עЧԪشch0ŵԪʼ洢 + */ +typedef struct { + char* ch; // Ƿǿմ򰴴洢chΪNULL + int length; +} HString; + + +/* + * ʼ + * + * һֵΪcharsĴT + * + *ע + * òСӼ + */ +Status StrAssign(HString* T, const char* chars); + +/* + * Ƚ + * + * ȽϴSʹTرȽϽ + * + *ע + * òСӼ + */ +Status StrCompare(HString S, HString T); + +/* + * + * + * SƵT + */ +Status StrCopy(HString* T, HString S); + +#endif diff --git a/VisualC++/CourseBook/0405_WordList/TestData.txt b/VisualC++/CourseBook/0405_WordList/TestData.txt new file mode 100644 index 0000000..9b3437f --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/TestData.txt @@ -0,0 +1,7 @@ + + 005 Computer Data Structures + 010 Introduction to Data Structures + 023 Fundamentals of Data Structures + 034 The Design and Analysis of Computer Algorithms + 050 Introduction to Numerical Analysis + 067 Numerical Analysis diff --git a/VisualC++/CourseBook/0405_WordList/WordList-main.c b/VisualC++/CourseBook/0405_WordList/WordList-main.c new file mode 100644 index 0000000..70fb3b3 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/WordList-main.c @@ -0,0 +1,27 @@ +#include // ṩsystemԭ +#include "WordList.h" //**04 **// + +int main(int argc, char** argv) { + FILE* fp; + char line[MaxLineLen]; + + char* bookinfo = "TestData.txt"; // Ŀļ + char* bookidx = "BookIdx.txt"; // ؼļ + + // + Main(bookinfo, bookidx); + + // ʾĻ + if((fp = fopen(bookidx, "r"))!=NULL) { + printf("---------ɹ---------\n\n"); + + while(feof(fp)==FALSE) { + fgets(line, MaxLineLen, fp); + printf("%s", line); + } + } else { + printf("---------δ---------\n"); + } + + return 0; +} diff --git a/VisualC++/CourseBook/0405_WordList/WordList.c b/VisualC++/CourseBook/0405_WordList/WordList.c new file mode 100644 index 0000000..a22baf1 --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/WordList.c @@ -0,0 +1,308 @@ +/*=========================================== + * + * + * 㷨: 4.94.104.114.124.134.14 + ============================================*/ + +#include "WordList.h" //**04 **// + +/* + * 㷨4.9 + * + * ļbookinfoжȡĿϢ˴ӦĹؼȻдļbookidx + */ +void Main(char* bookinfo, char* bookidx) { + FILE* f, * g; + char head[MaxLineLen]; // ĿıͷϢδʹã + IdxListType idxlist; // ؼ + ElemType bno; // + int count; + + // ԡֻģʽĿļ + if((f = fopen(bookinfo, "r")) != NULL) { + + // ԡֻдģʽļ + if((g = fopen(bookidx, "w")) != NULL) { + + // ʼ + InitIdxList(&idxlist); + + // ļһ + fgets(head, MaxLineLen, f); + + count = 0; + + // δļβһֱļ + while(feof(f) == FALSE && count < MaxBookNum) { + + // ļfһĿϢĿgBuf + GetLine(f); + + // gBufȡؼʵʱgWdListŴbno + ExtractKeyWord(&bno); + + // żӦĹؼʲidxlist + InsIdxList(&idxlist, bno); + + count++; + } + + // ļgд + PutText(g, idxlist); + + fclose(g); + } + + fclose(f); + } +} + +/* + * ʼ + * + *ע + * ̲нͷΪմ趨һıͷ + */ +void InitIdxList(IdxListType* idxlist) { + // ıͷϢ + char* chars = "ؼ "; + IdxTermType e; + + // ʼͷϢ + StrAssign(&(e.key), chars); + + // ʼ + InitList(&(e.bnolist)); + + (*idxlist).item[0] = e; + + // ͷΪ0Ϣ + (*idxlist).last = 0; +} + +/* + * ļfжȡһĿϢĿgBuf + */ +void GetLine(FILE* f) { + // ȡһݣ뻺gBuf + fgets(gBuf, MaxLineLen, f); +} + +/* + * ӻgBufȡؼʵʱgWdListŴbno + */ +void ExtractKeyWord(ElemType* bno) { + char delim[] = {'-', ' ', '\r', '\n', '\t'}; // ָ + char* title; // + char* token; // зֽĹؼ + + // ֽĿַŴbno(ʮ)titleָʣµַ() + *bno = (int) strtol(gBuf, &title, 10); + + // ɴдСд + strlwr(title); + + // չؼʴʱ + gWdList.last = 0; + + // ֽؼ + for(token = strtok(title, delim); token != NULL; token = strtok(NULL, delim)) { + // ùؼdzôʣ + if(isCommonWords(token) == TRUE) { + continue; + } + + // ´ȡĹؼ + gWdList.item[gWdList.last++] = token; + } +} + +/* + * 㷨4.10 + * + * bnoӦеĹؼʰʵ˳뵽idxlist + */ +Status InsIdxList(IdxListType* idxlist, int bno) { + int i, j; + Boolean boo; + HString wd; + + if(gWdList.last <= 0) { + return ERROR; + } + + // bnoӦейؼ + for(i = 0; i < gWdList.last; i++) { + // ȡĹؼ + GetWord(i, &wd); + + // жϸùؼǷѾλ + j = Locate(*idxlist, wd, &boo); + + // ùؼʲУҪؼ + if(boo == FALSE) { + // ؼwd뵽 + InsertNewKey(idxlist, j, wd); + } + + // ڹؼѴڵ£ + if(!InsertBook(idxlist, j, bno)) { + return ERROR; + } + } + + return OK; +} + +/* + * 㷨4.11 + * + * wdشʱgWdListеiؼʡ + */ +void GetWord(int i, HString* wd) { + if(i < 0 || i > gWdList.last - 1) { + StrAssign(wd, ""); + } else { + StrAssign(wd, gWdList.item[i]); + } +} + +/* + * 㷨4.12 + * + * ѯidxlistǷwdȵĹؼʡ + * ڣ򷵻wdڴʱеλãbΪTRUE + * ڣ򷵻wdӦλãbΪFALSE + */ +int Locate(IdxListType idxlist, HString wd, Boolean* b) { + int i, m = -1; + + /* + * idxlistвҹؼwdǷ + * ע0ŵԪ洢˱ͷϢ + */ + for(i = idxlist.last; i > 0 && (m = StrCompare(idxlist.item[i].key, wd)) > 0; i--) { + } + + // ҵ˹ؼwd + if(m == 0) { + *b = TRUE; + return i; + } else { + *b = FALSE; + return i + 1; + } +} + +/* + * 㷨4.13 + * + * i(>=0)ؼwdʼΪձ + */ +void InsertNewKey(IdxListType* idxlist, int i, HString wd) { + int j; + + /* + * + * ע0ŵԪ洢˱ͷϢ + */ + for(j = (*idxlist).last; j >= i; j--) { + (*idxlist).item[j + 1] = (*idxlist).item[j]; + } + + // + StrCopy(&((*idxlist).item[i].key), wd); + + // ʼ + InitList(&((*idxlist).item[i].bnolist)); + + // Ŀһ + (*idxlist).last++; +} + +/* + * 㷨4.14 + * + * Ϊi(>0)Ĺؼʲš + */ +Status InsertBook(IdxListType* idxlist, int i, ElemType bno) { + Link p; + + // ڴʧ + if(MakeNode(&p, bno) == FALSE) { + return ERROR; + } + + // µ + Append(&((*idxlist).item[i].bnolist), p); + + return OK; +} + +/* + * ɵidxlistļg + */ +void PutText(FILE* g, IdxListType idxlist) { + int i, j, m, n; + Link p; + HString S; + ELinkList L; + + if(idxlist.last <= 0) { + return; + } + + // ͷϢ + S = idxlist.item[0].key; + for(m = 0; m < S.length; m++) { + fprintf(g, "%c", S.ch[m]); + } + fprintf(g, "\n"); + + // Ϣ + for(i = 1; i <= idxlist.last; i++) { + // 1.ؼ + S = idxlist.item[i].key; + for(m = 0; m < S.length; m++) { + fprintf(g, "%c", S.ch[m]); + } + + // 2.ո + for(j = 1; j <= 18 - idxlist.item[i].key.length; j++) { + fprintf(g, " "); + } + + // 3. + L = idxlist.item[i].bnolist; + for(n = 1, p = L.head->next; n <= L.len; n++) { + fprintf(g, "%03d", p->data); + p = p->next; + if(p) { + fprintf(g, ""); + } + } + + // 4. + fprintf(g, "\n"); + } + +} + +// жstrǷΪô +static Status isCommonWords(char* str) { + int i; + + // ôʴʱЩʻᱻųڹؼ֮ + WordListType words = {{"a", "an", "the", "of", "and", "is", "to", "as", "in", "for"}, 10}; + + // ѯôʴʱ + for(i = 0; i < words.last; i++) { + // ַкԴСдıȽ + if(strcmpi(str, words.item[i]) == 0) { + // ַdzôʣ򷵻TRUE + return TRUE; + } + } + + return FALSE; +} diff --git a/VisualC++/CourseBook/0405_WordList/WordList.h b/VisualC++/CourseBook/0405_WordList/WordList.h new file mode 100644 index 0000000..b43a31c --- /dev/null +++ b/VisualC++/CourseBook/0405_WordList/WordList.h @@ -0,0 +1,130 @@ +/*=========================================== + * + * + * 㷨: 4.94.104.114.124.134.14 + ============================================*/ + +#ifndef WORDLIST_H +#define WORDLIST_H + +#include // ṩfopenfclosefeoffgetsԭ +#include // ṩexitstrtolԭ +#include // ṩstrlenstrcmpistrlwrԭ +#include "Status.h" //**01 **// +#include "ELinkList.h" //**02 Ա**// +#include "HString.h" //**04 **// + +/* 궨 */ +#define MaxBookNum 1000 // Ŀֻ1000齨 +#define MaxKeyNum 2500 // (ֵ) +#define MaxLineLen 500 // Ŀ()󳤶 +#define MaxWordNum 100 // ʱ + +/* Ͷ */ + +// +typedef Status Boolean; + +// ʱ(˳) +typedef struct { + char* item[MaxWordNum]; // ʱ + int last; // ʱij +} WordListType; + +// ͣУ +typedef struct { + HString key; // ؼ + ELinkList bnolist; // +} IdxTermType; + +/* + * + * + *ע + * 0ŵԪ洢ͷϢһ̲ͬ + */ +typedef struct { + IdxTermType item[MaxKeyNum + 1]; // ļ + int last; // аĿ +} IdxListType; + +/* ȫֱǰ涼gǣ */ + +// Ŀ +char gBuf[MaxLineLen]; + +// ؼʴʱ(ͨʱ)Ѿų˳ô +WordListType gWdList; + + +/* + * 㷨4.9 + * + * ļbookinfoжȡĿϢ˴ӦĹؼȻдļbookidx + */ +void Main(char* bookinfo, char* bookidx); + +/* + * ʼ + * + *ע + * ̲нͷΪմ趨һıͷ + */ +void InitIdxList(IdxListType* idxlist); + +/* + * ļfжȡһĿϢĿgBuf + */ +void GetLine(FILE* f); + +/* + * ӻgBufȡؼʵʱgWdListŴbno + */ +void ExtractKeyWord(ElemType* bno); + +/* + * 㷨4.10 + * + * bnoӦؼʰʵ˳뵽idxlist + */ +Status InsIdxList(IdxListType* idxlist, int bno); + +/* + * 㷨4.11 + * + * wdشʱgWdListеiؼʡ + */ +void GetWord(int i, HString* wd); + +/* + * 㷨4.12 + * + * ѯidxlistǷwdȵĹؼʡ + * ڣ򷵻wdڴʱеλãbΪTRUE + * ڣ򷵻wdӦλãbΪFALSE + */ +int Locate(IdxListType idxlist, HString wd, Boolean* b); + +/* + * 㷨4.13 + * + * i(>=0)ؼwdʼΪձ + */ +void InsertNewKey(IdxListType* idxlist, int i, HString wd); + +/* + * 㷨4.14 + * + * Ϊi(>0)Ĺؼʲš + */ +Status InsertBook(IdxListType* idxlist, int i, int bno); + +/* + * ɵidxlistļg + */ +void PutText(FILE* g, IdxListType idxlist); + +// жstrǷΪô +static Status isCommonWords(char* str); + +#endif diff --git a/VisualC++/CourseBook/CourseBook.sdf b/VisualC++/CourseBook/CourseBook.sdf index d8a2bcd..e9c6980 100644 Binary files a/VisualC++/CourseBook/CourseBook.sdf and b/VisualC++/CourseBook/CourseBook.sdf differ diff --git a/VisualC++/CourseBook/CourseBook.sln b/VisualC++/CourseBook/CourseBook.sln index 3f49e50..c7d5cd2 100644 --- a/VisualC++/CourseBook/CourseBook.sln +++ b/VisualC++/CourseBook/CourseBook.sln @@ -47,6 +47,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "0402_HString", "0402_HStrin EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "0403_LString", "0403_LString\0403_LString.vcxproj", "{6D29CF1A-DFF3-4730-A587-EEEA5B3673F2}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "0404_KMP", "0404_KMP\0404_KMP.vcxproj", "{5D2A1F0B-F177-43A9-873A-56C7E08E6987}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "0405_WordList", "0405_WordList\0405_WordList.vcxproj", "{FA2740D7-2D96-4F57-AE79-FCDA5C13CA86}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -145,6 +149,14 @@ Global {6D29CF1A-DFF3-4730-A587-EEEA5B3673F2}.Debug|Win32.Build.0 = Debug|Win32 {6D29CF1A-DFF3-4730-A587-EEEA5B3673F2}.Release|Win32.ActiveCfg = Release|Win32 {6D29CF1A-DFF3-4730-A587-EEEA5B3673F2}.Release|Win32.Build.0 = Release|Win32 + {5D2A1F0B-F177-43A9-873A-56C7E08E6987}.Debug|Win32.ActiveCfg = Debug|Win32 + {5D2A1F0B-F177-43A9-873A-56C7E08E6987}.Debug|Win32.Build.0 = Debug|Win32 + {5D2A1F0B-F177-43A9-873A-56C7E08E6987}.Release|Win32.ActiveCfg = Release|Win32 + {5D2A1F0B-F177-43A9-873A-56C7E08E6987}.Release|Win32.Build.0 = Release|Win32 + {FA2740D7-2D96-4F57-AE79-FCDA5C13CA86}.Debug|Win32.ActiveCfg = Debug|Win32 + {FA2740D7-2D96-4F57-AE79-FCDA5C13CA86}.Debug|Win32.Build.0 = Debug|Win32 + {FA2740D7-2D96-4F57-AE79-FCDA5C13CA86}.Release|Win32.ActiveCfg = Release|Win32 + {FA2740D7-2D96-4F57-AE79-FCDA5C13CA86}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/VisualC++/CourseBook/CourseBook.suo b/VisualC++/CourseBook/CourseBook.suo index c2b2244..1b0aa7f 100644 Binary files a/VisualC++/CourseBook/CourseBook.suo and b/VisualC++/CourseBook/CourseBook.suo differ