public int RecursiveTree(SpanningTree parent, Cell currentCell) { int length = 0; int maxLength = 0; parent.row = currentCell.row; parent.col = currentCell.col; graph.graph[currentCell.row][currentCell.col].visited = true; EnumCell enumCell = new EnumCell(currentCell.row, currentCell.col, graph.graph); foreach (Cell cell in enumCell) { if (!cell.visited) { SpanningTree newBranch = new SpanningTree(); if (parent.children == null) { parent.children = new List <SpanningTree>(); } length = RecursiveTree(newBranch, SpanningTree.graph.graph[cell.row][cell.col]); if (length > maxLength) { if ((enumCell.numberOfRows > 7) || (enumCell.numberOfCols > 7)) { if (parent.children.Count == 0) { parent.children.Add(newBranch); } else { parent.children[0] = newBranch; } } else { parent.children.Add(newBranch); } maxLength = length; } } } graph.graph[currentCell.row][currentCell.col].visited = false; parent.length = maxLength; return(maxLength + 1); }
public int RecursiveTree(SpanningTree parent, Cell currentCell) { int length = 0; int maxLength = 0; parent.row = currentCell.row; parent.col = currentCell.col; graph.graph[currentCell.row][currentCell.col].visited = true; if ((currentCell.col == 1) && (currentCell.row == 3)) { int z = 5; } if ((currentCell.col == 0) && (currentCell.row == 2)) { int zz = 5; } EnumCell enumCell = new EnumCell(currentCell.row, currentCell.col, graph.graph); foreach (Cell cell in enumCell) { if (!cell.visited) { SpanningTree newBranch = new SpanningTree(); if (parent.children == null) { parent.children = new List <SpanningTree>(); } parent.children.Add(newBranch); length = RecursiveTree(newBranch, SpanningTree.graph.graph[cell.row][cell.col]); if (length > maxLength) { maxLength = length; } } } graph.graph[currentCell.row][currentCell.col].visited = false; parent.length = maxLength; return(maxLength + 1); }