Ejemplo n.º 1
0
        static void Main()
        {
            Tree<int> tree =
            new Tree<int>(7,
                          new Tree<int>(19,
                                        new Tree<int>(1),
                                        new Tree<int>(12),
                                        new Tree<int>(31)),
                          new Tree<int>(21),
                          new Tree<int>(14,
                                        new Tree<int>(23),
                                        new Tree<int>(6)));

            //Console.WriteLine(tree.Root.Value);

            tree.AllPathsWithGivenSum(28);
            //Console.WriteLine("Depth-First Search (DFS) traversal (recursive):");
               // tree.TraverseDFS();
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var tree =
                new Tree<int>(7,
                    new Tree<int>(19,
                        new Tree<int>(1),
                        new Tree<int>(12),
                        new Tree<int>(31)),
                    new Tree<int>(21),
                    new Tree<int>(14,
                        new Tree<int>(23),
                        new Tree<int>(6)));

            Console.WriteLine("Tree (indented):");
            tree.Print();

            Console.Write("Tree nodes:");
            tree.Each(c => Console.Write(" " + c));
            Console.WriteLine();

            Console.WriteLine();

            var binaryTree =
                new BinaryTree<string>("*",
                    new BinaryTree<string>("+",
                        new BinaryTree<string>("3"),
                        new BinaryTree<string>("2")),
                    new BinaryTree<string>("-",
                        new BinaryTree<string>("9"),
                        new BinaryTree<string>("6")));

            Console.WriteLine("Binary tree (indented, pre-order):");
            binaryTree.PrintIndentedPreOrder();

            Console.Write("Binary tree nodes (in-order):");
            binaryTree.EachInOrder(c => Console.Write(" " + c));
            Console.WriteLine();

            Console.Write("Binary tree nodes (post-order):");
            binaryTree.EachPostOrder(c => Console.Write(" " + c));
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            var tree = new Tree<int, int> {{10, 1}, {14, 1}, {7, 1}, {16, 1}, {12, 1}, {13, 1}, {11, 1}};

            // tree.Rec();
            //tree.Remove(12);
            //tree.Remove(16);
            //tree.Remove(13);
            //tree.Remove(11);
            //tree.Remove(14);
            //tree.Remove(7);
            //tree.Remove(10);
            //Console.WriteLine();
            //tree.Rec();
            //tree.GetAllKeys();
            foreach (var key in tree)
            {
                Console.Write(key + " ");
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Tree tree = new Tree();
            tree.Root.value = "F";
            var b = tree.InsertChild(tree.Root, "B");
            var g = tree.InsertChild(tree.Root, "G");
            var a = tree.InsertChild(b, "A");
            var d = tree.InsertChild(b, "D");
            var c = tree.InsertChild(d, "C");
            var e = tree.InsertChild(d, "E");
            var i = tree.InsertChild(g, "I");
            var h = tree.InsertChild(i, "H");

            Console.Write("Pre-Order:\t");
            tree.PreOrder(tree.Root);
            Console.WriteLine();

            Console.Write("Post-Order:\t");
            tree.PostOrder(tree.Root);
            Console.WriteLine();

            Console.Write("In-Order:\t");
            tree.InOrder(tree.Root);
            Console.WriteLine();

            Console.Write("Level-Order:\t");
            tree.LevelOrder(tree.Root);
            Console.WriteLine();
        }