Here you can find the source of sortAccording2(int[] ary, Integer[] sortOrder)
public static void sortAccording2(int[] ary, Integer[] sortOrder)
//package com.java2s; //License from project: Apache License public class Main { /** Sort given array according given sort order. Sort is implemented in-place. */ public static void sortAccording2(int[] ary, Integer[] sortOrder) { Integer[] so = sortOrder.clone(); // we are modifying sortOrder to preserve exchanges for (int i = 0; i < ary.length; i++) { int tmp = ary[i]; int idx = so[i]; ary[i] = ary[idx];//from w w w .ja v a2 s. c o m ary[idx] = tmp; for (int j = i; j < so.length; j++) if (so[j] == i) { so[j] = idx; break; } } } /** Sort given array according given sort order. Sort is implemented in-place. */ public static void sortAccording2(boolean[] ary, Integer[] sortOrder) { Integer[] so = sortOrder.clone(); // we are modifying sortOrder to preserve exchanges for (int i = 0; i < ary.length; i++) { boolean tmp = ary[i]; int idx = so[i]; ary[i] = ary[idx]; ary[idx] = tmp; for (int j = i; j < so.length; j++) if (so[j] == i) { so[j] = idx; break; } } } }