Question: Please create unit tests for those three functions below. class MyLinkedListTest { @Test void testContainsSubsequence ( ) { } void testRemoveMaximumValues ( ) { }
Please create unit tests for those three functions below.
class MyLinkedListTest
@Test
void testContainsSubsequence
void testRemoveMaximumValues
void testReverse
public void reverse
if head null head.next null
return;
Node prev null;
Node current head;
Node next null;
while current null
next current.next;
current.next prev;
prev current;
current next;
head prev;
public Boolean containsSubsequenceMyLinkedList two
if two null
return null; Return null if 'two' is null
if twohead null
return true; An empty subsequence is always contained
Node current head;
while current null
Node subCurrent current;
Node otherCurrent two.head;
Try to match the sequence starting from current
while subCurrent null && otherCurrent null && subCurrent.value.equalsotherCurrentvalue
subCurrent subCurrent.next;
otherCurrent otherCurrent.next;
If we matched the entire 'two' list, return true
if otherCurrent null
return true;
current current.next;
return false; No match found
public void removeMaximumValuesint N
IMPLEMENT THIS METHOD!
MyLinkedList list this;
iflist null N
return;
find the maximum
java.util.PriorityQueue maxValues new java.util.PriorityQueuejavautil.Collections.reverseOrder;
Node current head;
while current null
if maxValues.containscurrentvalue
maxValues.addcurrentvalue;
if maxValuessize N
maxValues.poll;
current current.next;
current head;
Node prev null;
while current null
if maxValues.containscurrentvalue
if current head
removeFirst;
current head;
else if current tail
removeLast;
current null;
else
prev.next current.next;
current current.next;
size;
else
prev current;
current current.next;
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
