我将2D数组视为一个坐标,并尝试查找值为1的坐标值。
到目前为止,这是一个非常简单的BFS问题,但是我想做的就是看下图。
当我寻找1或找到全部之后,我想知道围绕边界的坐标值(按箭头顺序或其他方向)。
我需要添加哪些选项来获取这些信息?
下面是我现在使用的BFS代码。我可以从BFS函数获得坐标值,如第二张图片所示。
class Node
{
public int x;
public int y;
public Node(int x, int y)
{
this.x = x;
this.y = y;
}
};
private int[] dx = new int[8] { -1, 0, 1, 0, 1, -1, -1, 1 };
private int[] dy = new int[8] { 0, -1, 0, 1, 1, -1, 1, -1 };
private Queue<Node> q = new Queue<Node>();
bool[,] visit = new bool[15, 15];
int[,] coordinates = new int[15, 15] { { …Run Code Online (Sandbox Code Playgroud)