Question
1. Create a class Pair which stores two variables: key and value. Both fields should be generic implementing Comparable. Pair should have constructors, setters, getters,
1. Create a class Pair which stores two variables: key and value. Both fields should be generic implementing Comparable. Pair should have constructors, setters, getters, and a toString() method which relies on the toString() methods of the fields. (Every class in Java inherits a toString() method from the Object class, if this is not overridden elsewhere!)
2. Create a MAL class extending AL of Pair. MAL should also have a toString() method, a qs() method implementing quicksort as in Figure 8.22, a stableQs() method implementing a stable adaptation of quicksort (if , and a binarySearch() method implementing binary search for a given value, returning the first matching Pair or null if no matching pair is found. Use the following for stableQs(): Create an auxilliary MAL of Pairs; each Pair is to contain the initial position in the old MAL as key and the old value as value. Then sort the array; if two Pairs have identical values, use the key to break the tie. After the new MAL has been sorted, rearrange the original MAL accordingly.
3. Fully unit test all the classes. You should have at least one test case demonstrating that stableQs() provides a stable sort of some input for which qs() does not. Have these tests display pre and post sorting lists.
/** * Quicksort algorithm (driver) public staticStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started