数据结构 字串的模式匹配 KMP算法
来源:互联网 发布:php ffmpeg 微信语音 编辑:程序博客网 时间:2024/05/22 07:53
#include <stdio.h>#include <stdlib.h>#define OK 1#define ERROR 0#define OVERFLOW -2typedef struct{char *ch;int length;}String;void Init_String(String &T){T.ch = NULL;T.length = 0;}int StrAssign(String &T, char *chars){int i;int len;char *p = chars;if (T.ch){free(T.ch);}for (len = 0;*p != '\0'; ++len,++p);if (!len){T.ch = NULL;T.length = 0;}else{T.ch = (char *)malloc(len * sizeof(char));if (!T.ch){exit(OVERFLOW);}for (i=0; i<len; i++){T.ch[i] = chars[i];}T.length = len;}return OK;}void get_next(String T, int next[]){int i = 0;int j = -1;next[0] = -1;while (i<T.length){if (j == -1 || T.ch[i] == T.ch[j]){++i;++j;next[i] = j;}else{j = next[j];}}}int Index_KMP(String S, String T, int pos){int i = pos;int j = -1;int next[255];get_next(T,next);while (i<S.length && j <T.length ){if (j == -1 || S.ch[i] == T.ch[j]){++i;++j;}else{j = next[j];}}if (j == T.length ){return i-T.length + 1 ;}elsereturn 0;}int main(){String S,T;Init_String(S);Init_String(T);StrAssign(S,"abcdefghijklmm");StrAssign(T,"cdef");printf("%d\n",Index_KMP(S,T,0));return 0;}
0 0
- 数据结构 字串的模式匹配 KMP算法
- 【数据结构】 串的模式匹配算法KMP
- 数据结构--KMP模式匹配算法
- 数据结构- 串的模式匹配算法:BF和 KMP算法
- 数据结构- 串的模式匹配算法:BF和 KMP算法
- 数据结构之串的KMP模式匹配算法的实现
- 大话数据结构十一:字符串的模式匹配(KMP算法)
- 数据结构之模式匹配KMP算法的next数组求解
- 数据结构之串的模式匹配算法(KMP)
- 大话数据结构十一:字符串的模式匹配(KMP算法)
- 数据结构-串-KMP模式匹配算法
- 数据结构 字符串模式匹配之KMP算法
- 数据结构学习:KMP模式匹配算法
- 数据结构-模式匹配串算法(KMP)
- 数据结构——串(朴素的模式匹配算法、KMP模式匹配算法)
- 模式匹配的KMP 算法
- 模式匹配的算法Kmp
- 数据结构 模式匹配(KMP)
- windows怎么与虚拟机linux共享?
- Graph Databases—Chapter 2 The NOSQL Phenomenon阅读笔记
- Android ProgressBar实现方法列表
- 数据结构 串(链式存储)的基本操作
- MapReduce中第三方jar的存放
- 数据结构 字串的模式匹配 KMP算法
- 限制输入框只能输入数字
- java 面试题: 使用监听来实现实时跟踪
- 合泰 HT66F30 上电 RAM初始化
- CodeForces 371D. Vessels
- linux0.11启动过程
- 折腾半径
- 数据结构 二叉树的建立与遍历
- Ubuntu + Win7 双系统 重装win7后进入不了Ubuntu