User:Margusmartsepp/Contributions/Java/Utils.java: Difference between revisions

no edit summary
(Created page with "<lang java> import java.util.ArrayList; import java.util.Collections; public class Utils<T extends Comparable<T>> { private void swap(ArrayList<T> data, int i, int j) { T t =...")
 
No edit summary
Line 3:
import java.util.Collections;
 
public class Utils<T extends Comparable<T>> {
private static <T> void swap(ArrayList<T> data, int i, int j) {
T t = data.get(i);
data.set(i, data.get(j));
Line 10:
}
 
public static ArrayList<Integer> mRange(int from, int to) {
ArrayList<Integer> result = new ArrayList<Integer>();
for (int i = from; i <= to; i++)
Line 17:
}
 
public static <T extends Comparable<? super T>> boolean nextPerm(ArrayList<T> data) {
// find the swaps
int c = -1, d = data.size();
Line 43:
}
 
public static <T extends Comparable<? super T>> ArrayList<ArrayList<T>> Permutations(ArrayList<T> d) {
@SuppressWarnings("unchecked")
public ArrayList<ArrayList<T>> Permutations(ArrayList<T> d) {
ArrayList<ArrayList<T>> result = new ArrayList<ArrayList<T>>();
Collections.sort(d);
do {
result.add((new ArrayList<T>) (d.clone());
} while (this.nextPerm(d));
return result;
}
Anonymous user