protected void Split(TX key, out CartesianTreeBase <TX, TY> l, out CartesianTreeBase <TX, TY> r) { CartesianTreeBase <TX, TY> newt = null; if (X.CompareTo(key) <= 0) { if (Right == null) { r = null; } else { Right.Split(key, out newt, out r); } l = new CartesianTreeBase <TX, TY>(X, Y, Left, newt); } else { if (Left == null) { l = null; } else { Left.Split(key, out l, out newt); } r = new CartesianTreeBase <TX, TY>(X, Y, newt, Right); } }
/// <summary> /// Merges two cartesian trees into one. Requires first to be left to second. /// </summary> /// <param name="left">Lesser tree (all keys are lesser than in the second tree)</param> /// <param name="right">Greater tree (all keys are greater than in the first tree)</param> /// <returns></returns> protected static CartesianTreeBase <TX, TY> Merge(CartesianTreeBase <TX, TY> left, CartesianTreeBase <TX, TY> right) { if (left == null) { return(right); } if (right == null) { return(left); } if (left.Y.CompareTo(right.Y) >= 0) { return(new CartesianTreeBase <TX, TY>(left.X, left.Y, left.Left, Merge(left.Right, right))); } else { return(new CartesianTreeBase <TX, TY>(right.X, right.Y, Merge(left, right.Left), right.Right)); } }
public CartesianTreeBase(TX x, TY y, CartesianTreeBase <TX, TY> left = null, CartesianTreeBase <TX, TY> right = null) : base(new Tuple <TX, TY>(x, y), left, right) { }