Question: This class contains a generic Node inner class like the examples you ve seen in the lecture, except it has a prev ( short for
This class contains a generic Node inner class like the examples youve seen in the lecture, except it has a prev short for previous instance variable in addition to next. Note that the data instance variable has the generic type T
This class uses the generic Node class. Note that every Node declaration is Node because every nodes data is one of the characters A C G or TThe constructors for this class are already written. Your job is to finish writing methods plus a main method for testing.
appendNode n
matchesNode startNode, String target
findString target
extractNode firstExtractedNode, Node lastExtractedNode
insertDNALinkedList insertMe, Node insertionPoint
reverse
transposeString transposon, String target
mainString args The comments in the methods will tell you what to do
First, try to complete the first four methods append matches, find, extract that we talked about in class. Then, begin working on implementing the last three methods insert reverse, and transpose
Reverse Method
The reverse method reverses the order of the nodes. Note that you are doing a similar problem for your homework, but on a singly linked list. Do you think the problem on your homework is harder or easier?
Transposon Method
This method removes sequence matching transposon, reverses it and inserts it back into this list immediately before target. It throws IllegalArgumentException if it can't find transposon or target. Hint: Use the methods you just wrote.
Main Method
In order to complete the main method, you will need to create your own test case. The code prompts you to specify a chromosome string, a transposon string, and a target string. These will be used to test the transpose method, which calls all the others. One way to test would be to use a real chromosome. The shortest human chromosome is million bases long.
package linked;
public class DNALinkedList
private static class Node
private T data;
private Node prev; previous
private Node next;
NodeT data
this.data data;
Returns data of prev node, this node, and next node. Uses if prev is
null, and if next is null.
public String toString
String s;
if prev null
s ;
else s prev.data.toString;
s data;
if next null
s ;
else
s next.data;
return s;
private Node head; head.prev is always null
private Node tail; tail.next is always null
public DNALinkedListString s
appends;
Used by extraction methods. Not for public use.
private DNALinkedListNode head, Node tail
this.head head;
head.prev null;
this.tail tail;
tail.next null;
Converts arg to nodes which are appended to end of this list.
public void appendString s
for int i; ich;
public String toString
String s "DNALinkedList: ;
if head null
s "Empty";
else
Node n head;
while n null
s ndata;
n nnext;
return s;
Appends n to tail of this list.
public void appendNode n
Corner case: empty list.
if tail null
nprev ;
nnext ;
head ;
tail ;
General case.
else
fill this in
Returns true if the nodes starting at startNode match the target string. For example,
if the linked list looks like this:
ABCDEF
and if startNode is the nd node B then matchesstartNodeBCDE should return true.
private boolean matchesNode startNode, String target
return false;
If this list contains a chain of nodes whose data is the target, returns
the node at the start of that chain. If the target appears multiple times
in this list, returns the first occurrence. If the target is not in this list,
returns null.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
