求助! 我将作为参数传递给函数的结构是:
我的查询上下文中的摘要代码
struct mine_index
{
int row, col;
};
struct miner
{
bool up, down, right, left;
};
can_solve(mine_index start, mine_index end, miner the_miner)
{
can_solve(start(row+1,col), end, miner the_miner);
return ;
}
下面给出了递归函数的完整代码
bool can_solve(mine_index start, mine_index end, miner the_miner)
{
bool solution[size-1][size-1]
for (int i=0; i<size; i++)
{
for (int j=0; j<size; j++)
{
solution[i][j]=0;
}
}
if(start.row==size-1 && start.col==size-1)//base case
{
solution[start.row][start.row]=1
return true;
{
if(start.row>=0 && start.row<size-1 && start.col>=0 && start.col<size-1) //
{
solution[start.row][start.col]=1;
}
if(can_solve(start(row+1,col), end, miner the_miner))
{
return true;
}
if(can_solve(start(row,col+1), end, miner the_miner))
{
return true;
}
if(can_solve(start(row-1,col), end, miner the_miner))
{
return true;
}
if(can_solve(start(start.row,start.col-1), end, miner the_miner))
{
return true;
}
}
这个声明是否有效,如果不是,那么有没有其他方法来声明这个。我正在使用递归函数。整个功能如下。我现在需要研究逻辑,但我只想知道我的语法是否正确?
最佳答案
您的代码中存在一些微不足道的语法错误。 例如:
- 使用关键字end
- 错误的开闭花括号。
- 等...
首先,我认为您应该尝试使用一些 C++ IDE(例如 CodeBlocks)编写代码。 IDE 会注意到您的语法错误。 在更正所有语法错误之前,您可以考虑在下一步中使用函数。
关于c++ - 如果结构作为递归函数中的参数传递,我如何初始化结构的成员变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46725571/