public static void Delete(TreeNode<Range> root, Range range) { TreeNode<Range> target = Find(root, range); if (target != null) { } }
public static TreeNode<Range> Find(TreeNode<Range> root, Range range) { while (root != null) { if (root.Value.Left > range.Right) root = root.Left; else if (root.Value.Right < range.Left) root = root.Right; else break; } return root != null && root.Value == range ? root : null; }
public static TreeNode<Range> InsertRangeNode(TreeNode<Range> root, Range range) { if (root == null) return new TreeNode<Range>(range); if (range.Left > root.Value.Right) { if (root.Right != null) root.Right = InsertRangeNode(root.Right, range); else root.Right = new TreeNode<Range>(range); } else if (range.Right < root.Value.Left) { if (root.Left != null) root.Left = InsertRangeNode(root.Left, range); else root.Left = new TreeNode<Range>(range); } else { if (root.Value.Left > range.Left) { root.Value.Left = range.Left; if (root.Left != null) root.Left = InsertToLeft(root.Left, root); } if (root.Value.Right < range.Right ) { root.Value.Right = range.Right; if (root.Right != null) root.Right = InsertToRight(root.Right, root); } } return root; }