public static DFSTraversal <T> CreateTraversal(Node <T> root)
        {
            DFSTraversal <T> tr = new DFSTraversal <T>();

            Traverse(root, tr);

            return(tr);
        }
Example #2
0
        static void Main(string[] args)
        {
            Node <int> root = CreateTree(10);

            //https://www.geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/
            var dfs = DFSTraversal <int> .CreateTraversal(root);

            var bfs = BFSTraversal <int> .Traverse(root);

            Console.ReadKey();
        }
        private static void Traverse(Node <T> node, DFSTraversal <T> tr)
        {
            if (node == null)
            {
                return;
            }

            tr.PreOrder.Enqueue(node);
            Traverse(node.Left, tr);
            tr.InOrder.Enqueue(node);
            Traverse(node.Right, tr);
            tr.PostOrder.Enqueue(node);
        }