Let\'s say I have the three following lists
A1
A2
A3
B1
B2
C1
C2
C3
C4
C5
I\'d like to combine them into a si
Implementation of Andrew Rollings' answer:
public List equimix(List> input) {
// sort biggest list to smallest list
Collections.sort(input, new Comparator>() {
public int compare(List a1, List a2) {
return a2.size() - a1.size();
}
});
List output = input.get(0);
for (int i = 1; i < input.size(); i++) {
output = equimix(output, input.get(i));
}
return output;
}
public List equimix(List listA, List listB) {
if (listB.size() > listA.size()) {
List temp;
temp = listB;
listB = listA;
listA = temp;
}
List output = listA;
double shiftCoeff = (double) listA.size() / listB.size();
double floatCounter = shiftCoeff;
for (String item : listB) {
int insertionIndex = (int) Math.round(floatCounter);
output.add(insertionIndex, item);
floatCounter += (1+shiftCoeff);
}
return output;
}