Hi I need to calculate all the possible combinations of n-elements without repetition, I am using the following code but Unfortunately when I have a lot of elements it takes too much to get all the combinations...
private void calculateCombinationThread(int index,
int n,
List<Ricerca> elements,
List<Ricerca> rsr,
ref List<List<Ricerca>> Combinations)
{
if (n == 0)
{
if (rsr.Count != 0)
{
List<Ricerca> rrr = new List<Ricerca>() { };
rrr.AddRange(rsr);
Combinations.Add(rrr);
}
return;
}
for (int i = index; i <= elements.Count - n && !outOfMemory; ++i)
{
rsr.Add(elements[i]);
calculateCombinationThread(i + 1, n - 1, elements, rsr, ref Combinations);
rsr.RemoveAt(rsr.Count - 1);
}
}
am I doing something wrong!?! is there a faster way to get all the combinations !?!