Files
GrokAlgorithms/Chapter5_BreadthFirstSearch/Program.cs
2025-07-27 22:07:09 +03:00

29 lines
957 B
C#

using GrokAlgorithms.Chapter5_BreadthFirstSearch;
int count = 0;
// Команда для построения дерева
TreeNode<int> BuildTreeCommand(int value, int depth, int branchingFactor)
{
var node = new TreeNode<int>(value) { Comment = $"{count++}" };
if (depth == 0) return node;
for (int i = 1; i <= branchingFactor; i++)
node.Children.Add(BuildTreeCommand(value + i * 10, depth - 1, branchingFactor));
return node;
}
// Команда для печати дерева
void PrintTreeCommand(TreeNode<int> node, string indent = "")
{
Console.WriteLine($"{indent}{node.Value} [{node.Comment}] {(node.Selected ? " Selected" : "")}");
foreach (var child in node.Children)
PrintTreeCommand(child, indent + " ");
}
var root = BuildTreeCommand(1, 3, 2);
var found = Bfs.Search(root, (num) => num > 25);
if (found != null)
found.Selected = true;
PrintTreeCommand(root);