Question: Please complete the following function as shown below and pass the following unit test as well. As an example, consider the original sequence [ A

Please complete the following function as shown below and pass the following unit test as well.
As an example, consider the original sequence
[A, B, C, D]
A few (but not all) of the valid subsequences are []; [A]; [A, B]; [B, D]; [A, B, D]
[B, A] is invalid because the order changed
[A, B, C, D, E] is invalid because E does not appear in the original
public class MyRawLinkedList {
private static final long serialVersionUID =1561306366555780559L;
static class Node {
private static final long serialVersionUID =-3505677833599614054L;
String value;
Node next = null;
Node(String value, Node next){
this.value = value;
this.next = next;
}
Node(String value){
this(value, 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 listToString(Node head){
String ret ="";
while (head != null){
ret +="\""+ head.value +(head.next == null ?"\"" : "\",");
head = head.next;
}
return "["+ ret +"]";
}
public static void print(Node head){
System.out.println(listToString(head));
}

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 Programming Questions!