Suppose we write the following Comparator: import structure5.*; import java.util.Iterator; import java.util.Comparator; import java.util.Scanner; public class RevComparator implements Comparator {...


Suppose we write the following Comparator:


import structure5.*;


import java.util.Iterator;


import java.util.Comparator;


import java.util.Scanner;


public class RevComparator implements Comparator

{


protected Comparator base; public RevComparator(Comparator baseCompare)

{


base = baseCompare;


}


public int compare(T a, T b)


{


return -base.compare(a,b);


}


}


 What happens when we construct:


MyVector v = new MyVector();

Scanner s = new Scanner(System.in);


while (s.hasNextInt())


{


v.add(s.nextInt());


}


Comparator c = new RevComparator(new IntegerComparator());

v.sort(c);


Nov 16, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here