// Nikunj Sonigara
import java.util.Arrays;
public class Main {
// Function to sort integer array b[]
// according to the order defined by a[]
static void pairSort(int[] a, char[] b, int n) {
// Creating an array of pairs
Pair[] pairArr = new Pair[n];
// Storing the respective array
// elements in pairs.
for (int i = 0; i < n; i++) {
pairArr[i] = new Pair(a[i], b[i]);
}
// Sorting the pair array.
Arrays.sort(pairArr);
// Modifying original arrays
for (int i = 0; i < n; i++) {
a[i] = pairArr[i].first;
b[i] = pairArr[i].second;
}
}
// Driver function
public static void main(String[] args) {
int[] a = {2, 1, 5, 4, 9, 3, 6, 7, 10, 8};
char[] b = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'};
int n = a.length;
// Function calling
pairSort(a, b, n);
// Printing the sorted arrays
for (int i = 0; i < n; i++) {
System.out.print(a[i] + " ");
}
System.out.println();
for (int i = 0; i < n; i++) {
System.out.print(b[i] + " ");
}
}
// Class representing a pair
static class Pair implements Comparable<Pair> {
int first;
char second;
public Pair(int first, char second) {
this.first = first;
this.second = second;
}
// Comparing pairs based on their first element
@Override
public int compareTo(Pair pair) {
return Integer.compare(this.first, pair.first);
}
}
}