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>();
                    }
                    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);
        }
Пример #2
0
 public static void PrintLongest(SpanningTree parent, int level)
 {
     Console.WriteLine("{0}Level : '{1}', Row : '{2}', Col : '{3}', Length : '{4}'", new string(' ', 4 * level), level, parent.row, parent.col, parent.length);
     if (parent.children != null)
     {
         PrintLongest(parent.children[0], level + 1);
     }
 }
Пример #3
0
 static void Main(string[] args)
 {
     new SpanningTree(0, 2, graph);
     SpanningTree.OrderHighLow(SpanningTree.root, 0);
     SpanningTree.Print(SpanningTree.root, 0);
     Console.WriteLine("Longest");
     SpanningTree.PrintLongest(SpanningTree.root, 0);
     Console.ReadLine();
 }
Пример #4
0
 public static void OrderHighLow(SpanningTree parent, int level)
 {
     parent.children = parent.children.OrderByDescending(x => x.length).ToList();
     if (parent.children != null)
     {
         foreach (SpanningTree child in parent.children)
         {
             Print(child, level + 1);
         }
     }
 }
 static void Main(string[] args)
 {
     new SpanningTree(0, 2, graph);
     SpanningTree.Print(SpanningTree.root, 0);
     Console.ReadLine();
 }