Question: There are someTODO in the class PEmpty and PNode. do the TODO please import java.util.ArrayList; import java.util.List; class PEmptyE extends Exception {} abstract class PList

There are some"TODO" in the class PEmpty and PNode. do the "TODO" please
 
import java.util.ArrayList; import java.util.List; class PEmptyE extends Exception {} abstract class PList { abstract int getElem () throws PEmptyE; abstract PList getRest () throws PEmptyE; abstract int length (); /** * Splits the current list in two at the given * index */ abstract Pair splitAt (int index); /** * Keep dividing the list in two until you reach * a base case; then merge the sorted lists * resulting from the recursive calls */ abstract PList mergeSort (); /** * The given list 'ns' is sorted; the current * list (this) is also sorted. Return a new * sorted list from these two lists. */ abstract PList merge (PList ns); static List toList (PList ns) { List result = new ArrayList<>(); while (true) { try { result.add(ns.getElem()); ns = ns.getRest(); } catch (PEmptyE e) { return result; } } } static PList fromList (List ns) { PList result = new PEmpty(); for (int i=0; i 
public class Pair { private final A fst; private final B snd; Pair (A fst, B snd) { this.fst = fst; this.snd = snd; } A getFst () { return fst; } B getSnd () { return snd; } } 
class PEmpty extends PList { int getElem() throws PEmptyE { throw new PEmptyE(); } PList getRest() throws PEmptyE { throw new PEmptyE(); } int length() { return 0; } Pair splitAt(int index) { return null; // TODO } PList mergeSort() { return null; // TODO } PList merge(PList ns) { return null; // TODO } } class PNode extends PList { private final int elem; private final PList rest; private final int len; PNode(int elem, PList rest) { this.elem = elem; this.rest = rest; this.len = rest.length() + 1; } int getElem() { return elem; } PList getRest() { return rest; } int length() { return len; } Pair splitAt(int index) { return null; // TODO } PList mergeSort() { return null; // TODO } PList merge(PList ns) { return null; // TODO } } 

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!