kmp table building algorithm
added code for linked list traversal