private static void FindConnectedCells(int row, int col, ConnectedArea newArea) { if (IsOutside(row, col)) { return; } if (layout[row, col] == '*') { return; } if (IsVisited(row, col)) { return; } newArea.Size++; MarkVisited(row, col); FindConnectedCells(row, col + 1, newArea); FindConnectedCells(row + 1, col, newArea); FindConnectedCells(row - 1, col, newArea); FindConnectedCells(row, col - 1, newArea); }
static void Main(string[] args) { int[] startPoint = FindConnectedArea(); while (null != startPoint) { ConnectedArea newArea = new ConnectedArea() { Row = startPoint[0], Column = startPoint[1] }; FindConnectedCells(startPoint[0], startPoint[1], newArea); areas.Add(newArea); startPoint = FindConnectedArea(); } PrintAreas(areas); }