import java.util.Arrays; // only for debugging purposes /* An instance of this class employs the (parallel version of the) RankSort ** algorithm to sort an array of integers. */ public class RankSorterParallel { /* Rearranges the elements of the given array so that they are in ** ascending order. */ public void sort(int[] ary) { ArrayRankerParallel arp = new ArrayRankerParallel(); int[] ranks = arp.ranksOf(ary); ArrayPermuterParallel app = new ArrayPermuterParallel(); app.permuteAry(ary, ranks); } /* Returns a new array that contains the same elements as the given array, ** but in ascending order. */ public int[] sorted(int[] ary) { ArrayRankerParallel arp = new ArrayRankerParallel(); int[] ranks = arp.ranksOf(ary); ArrayPermuterParallel app = new ArrayPermuterParallel(); return app.permutationOf(ary, ranks); } // main() (for testing purposes) // ----------------------------- public static void main(String[] args) { int[] a = new int[] { 5, -2, 23, 17, 3, -6, 29, 13, 17, 5, 0, 18, 14, 0, 27, 42, -2, 9, 5, 6, 19, 33, 35, 26, 8 }; System.out.printf("Array: %s\n", Arrays.toString(a)); RankSorterParallel rsp = new RankSorterParallel(); int[] sorted = rsp.sorted(a); System.out.printf("Sorted version: %s\n", Arrays.toString(sorted)); rsp.sort(a); System.out.printf("After sorting: %s\n", Arrays.toString(a)); } }