查找列表中所有可能对的最快捷方式是什么?

Mic*_*cah 3 language-agnostic algorithm round-robin

基本上我有玩家名单,我想把它们配对,这样每个玩家都会玩一次.找到这些数据的最快方法是什么?

vla*_*lad 5

假设玩家没有两次出现在列表中,双for循环非常快:

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
Run Code Online (Sandbox Code Playgroud)