Linked list in Java - comparing two lists -


i need create recursive method in java checks 2 char lists. if second list includes chars in first list @ least once , in same order should return true, else should return false. example:

list 1: "abbcd"(every char in node), list 2: "abbcccddd"(every char in node) should return true.

example 2: "abbcd", list 2: "abcd" should return false.

i have ideas can't reach definite solution. ideas anyone?

i'll assume use usual node structure data element , reference next node. 1 can define function follows:

  • contains(null, haystack) = true (since every string contains empty string)

  • contains(pattern, null) = false (since empty string doesn't contain patterns)

  • contains(pattern, haystack) = contains(pattern.next, haystack.next) if pattern.data = haystack.data (we found match , proceed next item in both lists)

  • contains(pattern, haystack) = contains(pattern.next, haystack.next) else (we found no match , try next character in haystack)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -