我得到了这行代码,它弹出数组的一个 int 将它保存到int element
然后从数组中删除它。然后在 return 语句中将 CountCriticalVotes(rest, blockIndex + element);
其添加到blockIndex
变量中,如果它在数组为空之前达到 10,则返回 1。但我的问题是,我不希望它在参数中将数组中的所有值相加,但只添加一个,然后将参数值恢复为原始状态,然后添加一个新的,恢复等......我该怎么做?
int NumCriticalVotes :: CountCriticalVotes(Vector<int> & blocks, int blockIndex)
{
if (blockIndex >= 10)
{
return 1;
}
if (blocks.isEmpty())
{
return 0;
} else {
int element = blocks.get(0);
Vector<int> rest = blocks;
rest.remove(0);
return CountCriticalVotes(rest, blockIndex + element);