COSC 122 Programming II
In this assignment you will design a class that implements the Comparer interface to sort an array of integers in a novel way.
- Teams
You are encouraged to work with a partner for this assignment. You and your partner should begin thinking about the problems and begin writing the code before lab time.
You may work by yourself if you prefer.
- Design a class named SpecialComparer
that implements the
Comparer interface to sort an array of integers in
a special way:
The client provides a single integer value called a pivot when creating an instance of SpecialComparer. All the elements less than that pivot value will appear before pivot in the sorted array, but they will be arranged in descending order. All the elements greater than the pivot will appear after the pivot in the sorted array, and these elements will be arranged in ascending order.
For example, given a static method named toString, which produces a readable, text representation of an integer array, the following client code fragment:
int[] list = { 12, 33, 19, 33, 20, 44, 51, 18, 20, 200, 671 }; System.out.println(toString(list)); sort(list, new SpecialComparer(20)); System.out.println(toString(list));would print
[12,33,19,33,20,44,51,18,20,200,671] [19,18,12,20,20,33,33,44,51,200,671] - Check out
Your finished class will be evaluated for correctness and compliance.