public static int Height <T>(BinaryTreeNode <T> root) { if (root == null) { return(0); } return(Math.Max(BinaryTreeUtilities.Height(root.Left), BinaryTreeUtilities.Height(root.Right)) + 1); }
public static BinaryTreeNode <int> CreateRandomBinaryTree(int count, int min, int max) { if (count == 0) { return(null); } int[] data = ArrayUtilities.CreateRandomArray(count, min, max); Random random = new Random(); BinaryTreeNode <int> root = new BinaryTreeNode <int> { Data = data[0] }; for (int i = 1; i < count; i++) { BinaryTreeUtilities.AddRandomNode(root, data[i]); } return(root); }