我正在尝试找到具有递归功能的特定项目中的专家技能的所有可能组合。但是我得到了错误的答案。
我为每个项目都有专家列表。我可以通过
访问每种技能的专家列表ExpertForSkill currentExpertList = currentProjectTeam.expertForSkill.get(skillNum);
我的递归函数是
public static List<ProjectAndTeam> recursiveExpertFinder(
int skillNum,
ProjectAndTeam currentProjectTeam,
List<ProjectAndTeam> projectAndTeams) {
if (skillNum == currentProjectTeam.project.skills.size()) {
return projectAndTeams;
} else {
ExpertForSkill currentExpertList = currentProjectTeam.expertForSkill.get(skillNum);
ExpertForSkill newExprtForSkill = new ExpertForSkill();
ProjectAndTeam newProjectAndTeam = new ProjectAndTeam();
newProjectAndTeam.project = currentProjectTeam.project;
for (Expert expert : currentExpertList.expertList) {
newExprtForSkill.skill = currentExpertList.skill;
newExprtForSkill.expertList.add(expert);
List<ExpertForSkill> newExpertList = new ArrayList<>();
newExpertList.add(newExprtForSkill);
newProjectAndTeam.expertForSkill = newExpertList;
projectAndTeams.add(newProjectAndTeam);
recursiveExpertFinder(skillNum + 1, currentProjectTeam, projectAndTeams);
}
return projectAndTeams;
}
}
我正在像调用递归函数
List<ProjectAndTeam> solutions = new ArrayList<>();
projectAndTeam = recursiveExpertFinder(0, currentProjectTeam, solutions);
我在这里做什么错了?
编辑: 我的专家名单就像
Skill 1 : A,B
Skill 2 : B
我期望输出类似
Skill 1:A
Skill 2:B
Skill 1:B
Skill 2:B
但是我得到的输出与输入相同
Skill 1 : <A,B>
Skill 2 : <B>