什么是找到列表中的所有可能的对的最快方法?最快、方法、列表中

2023-09-11 23:09:30 作者:妞,给爷笑一个

基本上我的球员名单,我想配对起来,使每个玩家将扮演人人一次。什么是找到这个数据的最快方法是什么?

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?

推荐答案

假设选手不出现在列表两次,双循环是非常快:

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