public class FBSort { public static void mainB(int n) { int[] list = new int[n]; for (int i = 0; i < n; i++) { list[i] = Utils.makeRandom(n * 10); } printList(list); list = fbSort(list); System.out.println(); printList(list); } public static void mainT(int n) { int[] list = new int[n]; for (int i = 0; i < n; i++) { list[i] = Utils.makeRandom(n * 10); } long st = System.nanoTime(); fbSort(list); long fn = System.nanoTime(); System.out.println(fn - st); } public static void main(String[] args) { int l = Integer.parseInt(args[0]); mainT(l); } public static void printList(int[] arr) { for (int i = 0; i < arr.length; i++) { System.out.println(i + " " + arr[i]); } } public static int[] fbSort(int[] temp) { int[] result = new int[temp.length]; for (int i = 0; i < temp.length; i++) { int bestloc = -1; for (int j = 0; j < temp.length; j++) { if (temp[j] >= 0) { if (bestloc < 0) { bestloc = j; } else { if (temp[bestloc] > temp[j]) { bestloc = j; } } } } result[i] = temp[bestloc]; temp[bestloc] = -1; } return result; } }