Ejemplo n.º 1
0
        private int GetMaxDepth(BNode node, ref bool balanced)
        {
            int maxLeft = 0;
            int maxRight = 0;
            int maxCur = 0;

            if (node.Left == null && node.Right == null) {
                return 0;
            }

            if (node.Left != null) {
                maxLeft = GetMaxDepth(node.Left, ref balanced);
            }
            if (node.Right != null) {
                maxRight = GetMaxDepth(node.Right, ref balanced);
            }
            maxCur = (maxLeft > maxRight) ? maxLeft + 1 : maxRight + 1;

            if (Math.Abs(maxLeft - maxRight) > 1) {
                Console.WriteLine("not balanced at: {0} - {1}:{2}", node.Data, maxLeft, maxRight);
                balanced = false;
            }

            return maxCur;
        }
Ejemplo n.º 2
0
 public void PreOrder(BNode node)
 {
     if (node == null)
         return;
     Console.WriteLine(" {0} ", node.Data);
     PreOrder(node.Left);
     PreOrder(node.Right);
 }
Ejemplo n.º 3
0
        public void InOrder(BNode node)
        {
            if (node == null)
                return;

            InOrder(node.Left);
            Console.Write(" {0} ", node.Data);
            InOrder(node.Right);
        }