Anonymous user
Permutations by swapping: Difference between revisions
→{{header|Java}}
(adding Java implementation) |
|||
Line 1,263:
import java.util.Arrays;
import java.util.stream.IntStream;
Line 1,294 ⟶ 1,293:
void output(Object[] array, boolean plus) {
System.out.println(
}
Line 1,311 ⟶ 1,308:
void loop(Object[] array, int n) {
int[] c = new int[n];
output(array, true);
boolean plus = false;
for (int i = 0; i < n; ) {
if (c[i] < i) {
if (i % 2 == 0) {
Line 1,325 ⟶ 1,318:
}
output(array, plus);
plus
c[i]++;
i = 0;
Line 1,334 ⟶ 1,327:
}
}
}</lang>▼
{{out}}
▲</lang>
<pre>
[1, 0, 2, 3] -1
[2, 0, 1, 3] +1
Line 1,386 ⟶ 1,379:
[1, 0, 2, 3] +1
[0, 1, 2, 3] -1
</
=={{header|jq}}==
|