示例#1
0
 private int Height(BinaryTreeEx node)
 {
     if (node == null)
     {
         return(0);
     }
     return(1 + Math.Max(Height(node.leftNode), Height(node.rightNode)));
 }
示例#2
0
 public void PrintDFS(BinaryTreeEx node, string space)
 {
     Console.WriteLine(space + node.Value);
     if (node.leftNode != null)
     {
         PrintDFS(node.leftNode, space + " ");
     }
     if (node.rightNode != null)
     {
         PrintDFS(node.rightNode, space + " ");
     }
 }
示例#3
0
            // part 6: tells that binary tree is prefectly balanced: copied from Greekforgreek
            public bool IsBalanced(BinaryTreeEx node)
            {
                if (node == null)
                {
                    return(true);
                }

                LeftSubtreeHeight  = Height(node.leftNode);
                rightSubtreeHeight = Height(node.rightNode);

                if (Math.Abs(LeftSubtreeHeight - rightSubtreeHeight) <= 1)
                {
                    return(true);
                }
                return(false);
            }
示例#4
0
 public BinaryTreeEx(int value, BinaryTreeEx LN, BinaryTreeEx RN)
 {
     this.Value     = value;
     this.leftNode  = LN;
     this.rightNode = RN;
 }