Question: Task 4: Write a method called subsequence that given two linked lists of characters determines whether the shorter list (let us call it S) is

 Task 4: Write a method called subsequence that given two linked

Task 4: Write a method called subsequence that given two linked lists of characters determines whether the shorter list (let us call it S) is a subsequence of the longer list (let us call it L). If the shorter list is a subsequence of the longer list, then the method should return the length of the shortest segment in L that contains S as a subsequence. For example, for sequences CAT and ACAGTGCGTATAT from the above example, the method should return 4. If the shorter list is not a subsequence of the longer list, then the method should return value - 1. The method should have two parameters (of type CharNode) - heads of the two linked lists. It is not known in advance which of the parameters (the first one or the second one) contains a shorter list. The length of the lists must be checked first to determine which of the two given lists is shorter. (Note: The goal of this task is to practice working with linked lists. Converting lists into strings and using String methods is not permitted.) In your program you should prompt the user to enter two strings, convert the strings into linked lists using the method which you wrote before (to convert a String into a linked list of characters), call the method to determine whether a shorter list is a subsequence of a longer list and output the result

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!