摘要: 图文请参考:http://www.cnblogs.com/dolphin0520/archive/2011/08/24/2151846.html以下是我的理解。首先要理解next数组的存在意义:减少子串的回溯-》如何减少?构建next数组:首先数组第一位next[0]=-1;为什么是-1,其实它只是一个标识,表示现在已经是next数组的首位了,其实next[0]<0即可。 先看代码(递推法): 1 void getNext(char stringArray[],int next[]) 2 { 3 next[0]=-1;//NEXT数组第一位设为-1; 4 int ... 阅读全文
posted @ 2014-03-25 22:07 随心随想 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 学习笔记 1 #include 2 #include 3 4 5 void getNext(const char stringArray[]) 6 { 7 int next[100]; 8 next[0]=-1;//NEXT数组第一位设为-1; 9 int len=strlen(stringArray);10 11 int i=0,index=-1;12 //遍历子串得出NEXT数组 13 while(i<len)14 {15 //当子串没有任何匹配时或者当前字符与前缀字符相同 16 if... 阅读全文
posted @ 2014-03-25 20:48 随心随想 阅读(172) 评论(0) 推荐(0) 编辑