Пример #1
0
        static void Main(string[] args)
        {
            var tree = new Tree(2, 3);

            Console.WriteLine("[#]\nRecursive DFS:");
            tree.DFSRecursive();
            Console.WriteLine();

            Console.WriteLine("[#]\nRecursive Postorder DFS:");
            tree.DFSRecursivePostorder();
            Console.WriteLine();

            Console.WriteLine("[#]\nStack-based DFS:");
            tree.DFSStack();
            Console.WriteLine();

            Console.WriteLine("[#]\nQueue-based BFS:");
            tree.BFSQueue();
            Console.WriteLine();

            tree = new Tree(3, 2);
            Console.WriteLine("[#]\nRecursive Inorder DFS for Binary Tree:");
            tree.DFSRecursiveInorderBinary();
            Console.WriteLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("TreeTraversal");
            var tree = new Tree(3, 3);

            Console.WriteLine("StartDFSRecursive:");
            tree.StartDFSRecursive();
            Console.WriteLine("DFSStack:");
            tree.DFSStack();
            Console.WriteLine("DFSQueue:");
            tree.BFSQueue();
        }
Пример #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("TreeTraversal");
            var tree = new Tree(3, 3);

            Console.WriteLine("DFSRecursive:");
            tree.DFSRecursive();
            Console.WriteLine("DFSStack:");
            tree.DFSStack();
            Console.WriteLine("BFSQueue:");
            tree.BFSQueue();
            Console.WriteLine("DFSRecursivePostorder");
            tree.DFSRecursivePostorder();
            // Uncommenting the following 2 lines will result in an exception thrown because at least one Node of the Tree has more than 2 children and therefor a DFSRecursiveInorderBinary doesn't work.
            // Console.WriteLine("DFSRecursiveInorder (fail)");
            // tree.DFSRecursiveInorderBinary();
            tree = new Tree(3, 2);
            Console.WriteLine("DFSRecursiveInorder (succeed)");
            tree.DFSRecursiveInorderBinary();
        }