What's the quickest way to find all possible pairs in list?

前端 未结 4 788
走了就别回头了
走了就别回头了 2021-01-14 05:03

Basically I have list of players, and I want to pair them up so that each player will play everyone once. What\'s the quickest way to find this data?

4条回答
  •  离开以前
    2021-01-14 05:57

    assuming that players do not appear in the list twice, a double for loop is very quick:

    for (int i=0, i <= playerList.Count - 2, i++)
        for (int j=i+1, j <= playerList.Count - 1, j++)
            //add a new pairing of player i and j
    

提交回复
热议问题