什么是找到列表中的所有可能的对的最快方法? [英] What's the quickest way to find all possible pairs in list?

查看:125
本文介绍了什么是找到列表中的所有可能的对的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于什么是找到列表中的所有可能的对的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆