摘要: View Code void get_next(){ int i=-1,j=0; next[0]=-1; while(j<m-1) { if(i==-1||b[i]==b[j]) { ++i; ++j; next[j]=i;} else i=next[i]; }}int Index_KMP(){ int i=0,j=0; while(i<n && j<m) { if(a[i]==b[j]||j==-1) { ++i; ++j;} else j=next[j]; } if(j>=m) return i-m+1; else return -1;}代码:Vie 阅读全文
posted @ 2011-04-08 09:51 聊聊IT那些事 阅读(320) 评论(0) 推荐(0)