I try to translate an algorithm that generates all permutations of k out of n in C++ :
public void calculerEquipeTOT(ArrayList<Nageur> L, ArrayList<Nageur> F, int k) {
if (k == 0) {
if (calculerPointsTOT(L) > this.pointsMeilleureEquipe){
this.meilleureEquipe = L;
this.pointsMeilleureEquipe = calculerPointsTOT(meilleureEquipe);
}
} else {
for (Nageur x : F) {
ArrayList<Nageur> G = new ArrayList<Nageur>(F);
G.remove(G.indexOf(x));
ArrayList<Nageur> L2 = new ArrayList<Nageur>(L);
L2.add(x);
calculerEquipeTOT(L2, G, k - 1);
}
}
}
My problem is that the Lists could be Objects list and I don't know how to remove the x of the L2 list... I am not a C++ specialist, I managed it in Java but I have to do it in C++.
std::next_permutationactually?std::next_permutationwill help you in calculating all permutations of a range:std::vector<People> ps = ...; do { doSomething(ps); } while ( std::next_permutation(ps.begin(), ps.end()) );. See en.cppreference.com/w/cpp/algorithm/next_permutation for an example and detailed reference.