kmpsearch.h

来自「一个我的数据结构解题集合」· C头文件 代码 · 共 24 行

H
24
字号
#ifndef KMPSEARCH_H__
#define KMPSEARCH_H__

#include <string>
#include "Vector.h"
using namespace std;


/* 利用KMP算法在主串str中从pos开始搜索模式ptn,
 * 若找到返回第一次出现的位置, 否则返回str.size()
 */
int KmpSearch(const string& str, const string& ptn, int pos = 0);

/* 利用KMP算法在主串str中搜索所有模式ptn, (允许重叠)
 * 返回找到的下标的数组
 */
Vector<int> KmpSearchAll(const string& str, const string& ptn);

/* 利用KMP算法在主串str中搜索所有模式ptn, (不允许重叠)
 * 返回找到的下标的数组
 */
Vector<int> KmpSearchAllNoOverlap(const string& str, const string& ptn);

#endif // KMPSEARCH_H__

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?