public static int Height(Week7.Assignments.Node root) { if (root == null) { return(-1); } return(Math.Max(Height(root.Left), Height(root.Right)) + 1); }
public bool IsBST(Week7.Assignments.Node root, int min, int max) { if (root == null) { return(true); } if (root.Data < min || root.Data > max) { return(false); } return(IsBST(root.Left, min, root.Data) && IsBST(root.Right, root.Data, max)); }
public static int Diameter(Week7.Assignments.Node root) { if (root == null) { return(0); } int lh = Height(root.Left); int rh = Height(root.Right); int ld = Diameter(root.Left); int rd = Diameter(root.Right); return(Math.Max(lh + rh + 1, Math.Max(ld, rd))); }
public static Node TreeToLList(Week7.Assignments.Node root, Node hd, LinkedList <Node> list) { if (root == null) { return(hd); } TreeToLList(root.Left, hd, list); hd.Next = new Node { Data = root.Data }; hd = hd.Next; list.AddLast(hd); TreeToLList(root.Right, hd, list); return(head); }