public string PrintLevelOrder(Node_Tree root)
        {
            string result = String.Empty;


            if (root != null)
            {
                treeQueue.Enqueue(root);

                while (treeQueue.Count != 0)
                {
                    Node_Tree tree = treeQueue.Dequeue();

                    Console.Write("{0} ", tree.Data);

                    if (tree.Left != null)
                    {
                        treeQueue.Enqueue(tree.Left);
                    }

                    if (tree.Right != null)
                    {
                        treeQueue.Enqueue(tree.Right);
                    }
                }
            }

            return(result);
        }
示例#2
0
        public int GetHeight(Node_Tree node)
        {
            int height = 0;

            height = GetDepth(node) - 1;

            return(height);
        }
示例#3
0
        protected int GetDepth(Node_Tree node)
        {
            if (node == null)
            {
                return(0);
            }
            else
            {
                /* compute the depth of each subtree */
                int leftDepth  = GetDepth(node.Left);
                int rightDepth = GetDepth(node.Right);

                int maxDepth = Math.Max(leftDepth, rightDepth);
                return(maxDepth + 1);
            }
        }