Question: Please create unit tests for those three functions below. class MyRawLinkedListTest { @Test void testRawContainsSubsequence ( ) { } void testRawRemoveMaximumValues ( ) { }
Please create unit tests for those three functions below.
class MyRawLinkedListTest
@Test
void testRawContainsSubsequence
void testRawRemoveMaximumValues
void testRawReverse
Here are the functions:
public class MyRawLinkedList
private static final long serialVersionUID L;
static class Node
private static final long serialVersionUID L;
String value;
Node next null;
NodeString value, Node next
this.value value;
this.next next;
NodeString value
thisvalue null;
This is intentionally left private so that you can't erroneously try to
instantiate a new MyRawLinkedList
private MyRawLinkedList
These methods included as examples for how to use Node as a linked list.
public static String listToStringNode head
String ret ;
while head null
ret head.value headnext null : ;
head head.next;
return ret ;
public static void printNode head
System.out.printlnlistToStringhead;
public static void mainString args
Node list new NodeOne new NodeTwo new NodeThree null;
printlist;
Node argsaslist null;
for int i args.length ; i ; i
argsaslist new Nodeargsi argsaslist;
printargsaslist;
Node list null;
list new Nodea list;
list new Nodeb list;
list new Nodec list;
printlist;
Implement the methods below. Please do not change their signatures!
public static Node reverseNode head
IMPLEMENT THIS METHOD!
Node current head; current node that we are on
Node prev null; previous node that we have seen
Node next null; placeholder for the next node
while current null while we have not reached the end of the list
next current.next; set next to the next node
current.next prev; set the next pointer of the current node to the previous node
prev current; set prev to the current node
current next; set current to the next node
head prev; set head to the last node we saw, which is prev
return head; return the head of the reversed list
public static Node removeMaximumValuesNode head, int N
IMPLEMENT THIS METHOD!
find the maximum value in linked list datas are string type
Node current head; current node
String max current.value; max value
while current null loop through the linked list
if currentvalue.compareTomax compare the current value with max value
max current.value; if current value is greater than max value, then assign current value to max
current current.next; move to next node
remove the maximum value in linked list
current head; current node
Node prev null; previous node
while current null loop through the linked list
if currentvalue.equalsmax if current value is equal to max value
if prev null if previous node is null
head current.next; assign current node's next node to head
else
prev.next current.next; assign current node's next node to previous node's next node
N; decrement N
prev current; assign current node to previous node
current current.next; move to next node
return head; return head
public static boolean containsSubsequenceNode head, Node other
IMPLEMENT THIS METHOD!
if head null && other null if both head and other are null
return true;
if head null other null if one of head and other is null
return false;
if both head and other are not null
return head.value.equalsothervalue &&
containsSubsequenceheadnext, other.next
containsSubsequenceheadnext, other;
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
