以下是本人根据上一篇博客随笔http://www.cnblogs.com/jiayouwyhit/p/3251832.html,所写的KMP算法代码(暂未优化),个人认为在基于上一篇博客的基础上,代码的思路是相对很清晰的.以后的KMP算法求解建议依照此版本进行代码构思.再次强调下本版本的next数组: 例如: // T = a b c a b c a b c d //下标: 0 1 2 3 4 5 6 7 8 9 //next: -1 0 0 0 1 2 3 4 5 6该版本的next数组的一个
运行结果: Java代码: public class Main { public static void main(String[] args) { Global global=new Global(); philosopher ph[]=new philosopher[5]; int i; for(i=0;i<5;i++){ ph[i]=new philosopher(i); } Thread[] ph_t=new Thread[5]; for(i=0;i<5;i++){ ph_t[i]=n