Created
November 19, 2019 20:57
-
-
Save jenetics/b2063cd55174bded1f00baaa864ffcd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void sortStringArray() { | |
final String[] strings = new String[]{"g", "f", "r", "u", "a"}; | |
final int[] proxy = ProxySorter.sort( | |
strings, strings.length, | |
(a, i, j) -> a[i].compareTo(a[j]) | |
); | |
// Printing strings in ascending order. | |
for (int index : proxy) { | |
System.out.println(strings[index]); | |
} | |
} | |
void sortNodeList() { | |
final NodeList list = newNodeList(); | |
final int[] proxy = ProxySorter.sort( | |
list, list.getLength(), | |
(l, i, j) -> l.item(i).getNodeName().compareTo(l.item(j).getNodeName()) | |
); | |
// Print the XML nodes, sorted by node name. | |
for (int index : proxy) { | |
System.out.println(list.item(index).getNodeName()); | |
} | |
} | |
void sortIntFunction() { | |
final IntFunction<Double> function = i -> Math.sin(i/25.0); | |
final int[] proxy = ProxySorter.sort( | |
function, 100, | |
(f, i, j) -> Double.compare(f.apply(i), f.apply(j)) | |
); | |
// Printing the function values in ascending order. | |
for (int index : proxy) { | |
System.out.println(index + ": " + function.apply(index)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment