Rearranging
public static void rearrange(Comparable [] a, int [] r) {
Comparable [] u = new Comparable [a.length];
// Sort into u using ranks:
for (int i = 0; i < a.length; i++) {
u[r[i]] = a[i];
// Copy items back to array a.
for (int i = 0; i < a.length; i++) {
a[i] = u[i];
}
//(Sahni, p.80)
Previous slide
Next slide
Back to first slide
View graphic version