com.github.azbh111.utils.java.math.permutation.IntPermutationHolder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils-java Show documentation
Show all versions of utils-java Show documentation
com.github.azbh111:utils-java
The newest version!
package com.github.azbh111.utils.java.math.permutation;
import com.github.azbh111.utils.java.array.ArrayUtils;
/**
*
* @author pyz
* @date 2019/4/14 11:13 AM
*/
public class IntPermutationHolder extends PermutationHolder {
private int[] arr;
public IntPermutationHolder(int[] arr) {
this.arr = arr;
}
@Override
public int length() {
return arr.length;
}
@Override
public int compare(int i, int j) {
return Integer.compare(arr[i], arr[j]);
}
@Override
public void swap(int i, int j) {
int n = arr[i];
arr[i] = arr[j];
arr[j] = n;
}
@Override
public void reverse(int fromIndex, int toIndex) {
ArrayUtils.reverse(arr, fromIndex, toIndex);
}
}