public class Radix { public static void sortSales(String[] name, double[] data) { int n = data.length; quicksort(data, 0, n - 1); printData(name, data); } // Quick sort algorithm public static void quicksort(double[] data, int low, int high) { if (low < high) { int dp = partition(data, low, high); quicksort(data, low, dp - 1); quicksort(data, dp + 1, high); } } // partition data[low] to data[high] using data[low] as the pivot private static int partition (double[] data, int low, int high){ double pivot = data[low]; int i = low; for (int j = low + 1; j <= high; j++) if (data[j] < pivot) { ++i; swap(data, i, j); } //end for swap(data, low, i); return i; } // Exchange list[i] and list[j] values private static void swap ( double[] list, int i, int j){ double temp = list[i]; list[i] = list[j]; list[j] = temp; } private static void printData (String[] name,double[] data){ System.out.print("{"); for (int i = 0; i < data.length; i++) { System.out.print(name[i] + ": " + data[i] + ", "); } System.out.println("\b\b}"); } public static void main(String[] args) { sortSales(new String[]{"Russia", "Canada", "India"}, new double[]{40000.0, 20000.0, 30000.0}); sortSales(new String[]{"OZB", "fCJ", "VsX", "BlC", "KSN"}, new double[]{-15.0, -38.0, -13.0, 36.0, 45.0}); } }