I have a List of objects named Team and I want the optimal way to get all the possible pairs of objects. I've written an example:
public void GenerateMatches(Team team)
{
for(int i = 0; i < team.Count-1; i++)
{
for (int j = i + 1; j < team.Count; j++)
{
Console.WriteLine("Match:" + team[i].Name + " vs " + team[j].Name);
}
}
}
This is far from optimal but it works. Any better ideas?
Team1 vs Team2
is the same asTeam2 vs Team1
I assume that is what you meantN * (N - 1) / 2
items for all possible pairs; your solution is optimal in this meaningteam
, and then iterate it asteams
?