假设我有一个数组:
someArray = [["0","1","1","0"]
["0","1","0","1"]
["0","1","0","1"]
["0","1","1","0"]]
我想指出数组中的一个元素,然后能够识别每一个类似的“接触”元素(touch意味着如果将数组视为网格,它们将通过一个或多个连接进行连接)。例如,在本例中,如果我选择someArray[0][0],它会给我[1][0]、[2][0]和[3][0],因为所有这些元素都是“0”,并且彼此“接触”。我只指接触NESW,没有所说的方向的组合。在
我需要做些什么才能开始这项工作?在
编辑:原来这只是“洪水填充”。在
您可以考虑学习如何实现breadth-first searches和{a2},以实现您的目标。下面的示例说明如何在一个函数中轻松处理这两种搜索策略。模块化的方法应该使代码易于更改。在
相关问题 更多 >
编程相关推荐