【发布时间】:2018-05-07 18:54:47
【问题描述】:
我写这个是为了执行洪水填充,这里有两个问题:
1-我需要从用户那里获取length,如何将长度未知的数组传递给函数?
2-我应该更改在函数内部调用 Floodfill 的参数吗?
#include <stdio.h>
int main() {
const int length = 9;
int board[length][length],sheet[length][length];
int i=1,j=1;
floodfill(board,sheet,i,j);
return 0;
}
void floodfill(int board[length][length],int sheet[length][length], int i,int j){
if(board[i][j]!=-1)
{
sheet[i][j]= 1;
if(i-1>0 && j>0)
floodfill(board, sheet, i-1,j);
if(i+1>0 && j>0)
floodfill(board, sheet, i+1,j);
if(i>0 && j+1>0)
floodfill(board, sheet, i,j+1);
if(i>0 && j-1>0)
floodfill(board, sheet, i,j-1);
}
}
【问题讨论】:
-
这能编译吗?
-
@FelixPalmen 不