开发者

Implementing a recursion algorithm on a 3D array in c

I need to implement a function with the following s开发者_开发知识库ignature:

int rec(int board[SIZE][SIZE][10])

* SIZE is a const.

The function should be recursive. The board itself is 2 dimensional, and the 3rd dimension is used for holding the cell's possible values.

My question is: how can i scan the board recursivly, without the function accepting the current row and column of the board as parameters?


Does your function actually have to be recursive? You know there's only 3 dimensions to this array, so an algorithm that scans the entire array from start to finish can be implemented with nothing more than 3 nested for loops (2 to identify the current cell, and one to iterate over all 10 values in the cell).

On that note, when you say "holding the cell's possible values", does this cell actually have 10 separate ints that you need to track? If instead it's simply an int that has 10 possible distinct values, then that third dimension to the array is unnecessary. While there may be 10 possible values, the cell can only hold one of them at a time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜