|
1 | 1 | /* |
2 | 2 | * JavaPermutationTools: A Java library for computation on permutations and sequences |
3 | | - * Copyright 2005-2022 Vincent A. Cicirello, <https://www.cicirello.org/>. |
| 3 | + * Copyright 2005-2023 Vincent A. Cicirello, <https://www.cicirello.org/>. |
4 | 4 | * |
5 | 5 | * This file is part of JavaPermutationTools (https://jpt.cicirello.org/). |
6 | 6 | * |
@@ -605,9 +605,7 @@ public int get(int i) { |
605 | 605 | */ |
606 | 606 | public int[] get(int i, int j) { |
607 | 607 | if (j < i) throw new IllegalArgumentException("j must not be less than i"); |
608 | | - int[] array = new int[j - i + 1]; |
609 | | - System.arraycopy(permutation, i, array, 0, array.length); |
610 | | - return array; |
| 608 | + return Arrays.copyOfRange(permutation, i, j + 1); |
611 | 609 | } |
612 | 610 |
|
613 | 611 | /** |
@@ -776,11 +774,15 @@ public void reverse(int i, int j) { |
776 | 774 | public void removeAndInsert(int i, int j) { |
777 | 775 | if (i < j) { |
778 | 776 | int n = permutation[i]; |
779 | | - System.arraycopy(permutation, i + 1, permutation, i, j - i); |
| 777 | + for (int k = i; k < j; k++) { |
| 778 | + permutation[k] = permutation[k + 1]; |
| 779 | + } |
780 | 780 | permutation[j] = n; |
781 | 781 | } else if (i > j) { |
782 | 782 | int n = permutation[i]; |
783 | | - System.arraycopy(permutation, j, permutation, j + 1, i - j); |
| 783 | + for (int k = i; k > j; k--) { |
| 784 | + permutation[k] = permutation[k - 1]; |
| 785 | + } |
784 | 786 | permutation[j] = n; |
785 | 787 | } |
786 | 788 | } |
|
0 commit comments