
com.github.chen0040.si.utils.SortUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-swarm-intelligence Show documentation
Show all versions of java-swarm-intelligence Show documentation
Optimization library based on swarm-intelligence
The newest version!
package com.github.chen0040.si.utils;
import java.util.Comparator;
import java.util.List;
/**
* Created by xschen on 10/6/2017.
*/
public class SortUtil {
public static void exchange(List a, int i, int j){
T temp = a.get(i);
a.set(i, a.get(j));
a.set(j, temp);
}
public static boolean less(T a1, T a2, Comparator comparator){
return comparator.compare(a1,a2) < 0;
}
public static boolean isSorted(List a) {
for(int i=1; i < a.size(); ++i) {
if(less(a.get(i), a.get(i-1), Integer::compare)){
return false;
}
}
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy