// to do public bool Add(Interval interval) { if (root == null) { root = new BinarySearchIntervalTreeNode(interval); return(true); } else { return(PrivateAdd(root, interval)); } }
private bool PrivateAdd(BinarySearchIntervalTreeNode root, Interval interval) { if (interval.High <= root.NodeInterval.Low) { if (root.LeftNode == null) { root.LeftNode = new BinarySearchIntervalTreeNode(interval); return(true); } else { return(PrivateAdd(root.LeftNode, interval)); } } else if (interval.Low >= root.NodeInterval.High) { if (root.RightNode == null) { root.RightNode = new BinarySearchIntervalTreeNode(interval); return(true); } else { return(PrivateAdd(root.RightNode, interval)); } } else { return(false); /* root 10 , 20 * // interval low less than 20 * // or * // interval high is greater than 10 * // 7 9|10 goes to left * // 11, 25 overlap with root * // 11, 19 overlap with root * // 8,15 overlap with root * // 20|21, 25 goes to right */ } }