Example #1
0
    static void Main()
    {
        Tree <int> tree             = TreeReader.ReadIntegerTreeValues();
        int        deepestNodeValue = GetDeepestNode(tree);

        Console.WriteLine($"Deepest node: {deepestNodeValue}");
    }
Example #2
0
    static void Main()
    {
        Tree <int> tree = TreeReader.ReadIntegerTreeValues();

        List <int> longestPath = new List <int>();
        List <int> currentPath = new List <int>();

        FindLongestPath(tree, longestPath, currentPath);

        Console.WriteLine($"Longest path: {string.Join(" ", longestPath)}");
    }
Example #3
0
    static void Main()
    {
        Tree <int> tree = TreeReader.ReadIntegerTreeValues();

        List <int> result = new List <int>();

        GetLeaves(tree, result);
        result.Sort();

        Console.WriteLine($"Leaf nodes: {string.Join(" ", result)}");
    }
Example #4
0
    static void Main()
    {
        Tree <int> inputTree    = TreeReader.ReadIntegerTreeValues();
        int        requestedSum = int.Parse(Console.ReadLine());

        List <Tree <int> > subTrees = GetSubtreesWithGivenSum(inputTree, requestedSum);

        Console.WriteLine($"Subtrees of sum {requestedSum}:");
        subTrees.ForEach(st =>
        {
            st.Each(node => Console.Write($"{node} "));
            Console.WriteLine();
        }
                         );
    }
Example #5
0
    static void Main()
    {
        Tree <int> inputTree = TreeReader.ReadIntegerTreeValues();

        int requestedSum            = int.Parse(Console.ReadLine());
        List <List <int> > allPaths = new List <List <int> >();
        List <int>         path     = new List <int>();

        GetAllPathsWithAGivenSum(inputTree, allPaths, path, 0, requestedSum);

        Console.WriteLine($"Paths of sum {requestedSum}:");
        foreach (var currentPath in allPaths)
        {
            Console.WriteLine(string.Join(" ", currentPath));
        }
    }
Example #6
0
 static void Main()
 {
     inputTree = TreeReader.ReadIntegerTreeValues();
     Console.WriteLine($"Root node: {inputTree.Value}");
 }