public static int Sum(IntTreeNode clientRoot) { if (clientRoot == null) { return(0); } return(clientRoot.data + Sum(clientRoot.left) + Sum(clientRoot.right)); }
public static int Height(IntTreeNode clientRoot) { if (clientRoot == null) { return(0); } return(1 + Math.Max(Height(clientRoot.left), Height(clientRoot.right))); }
public static string ToStringInOrder(IntTreeNode clientRoot) { string str = ""; if (clientRoot != null) { str += ToStringInOrder(clientRoot.left) + " " + clientRoot.data + " " + ToStringInOrder(clientRoot.right) + " "; } return(str); }
public static bool ExistsST(IntTreeNode clientRoot, int value) { if (clientRoot == null) { return(false); } if (clientRoot.data == value) { return(true); } return(Exists(clientRoot.left, value) || Exists(clientRoot.right, value)); }
private IntTreeNode Add(IntTreeNode root, int value) { if (root == null) { root = new IntTreeNode(value); } else if (value <= root.data) { root.left = Add(root.left, value); } else { root.right = Add(root.right, value); } return(root); }
// Instance Methods public void Add(int value) { root = Add(root, value); }
// Constructor public IntSearchTree() { root = null; }
public IntTreeNode(int data, IntTreeNode left, IntTreeNode right) { this.data = data; this.left = left; this.right = right; }