public static SplitResult split(Node orig, int value) { NodePair lowerOther = splitBinary(orig, value); NodePair equalGreater = splitBinary(lowerOther.second, value + 1); return(new SplitResult(lowerOther.first, equalGreater.first, equalGreater.second)); }
public static NodePair splitBinary(Node orig, int value) { if (orig == null) { return(new NodePair(null, null)); } if (orig.x < value) { NodePair splitPair = splitBinary(orig.right, value); orig.right = splitPair.first; return(new NodePair(orig, splitPair.second)); } else { NodePair splitPair = splitBinary(orig.left, value); orig.left = splitPair.second; return(new NodePair(splitPair.first, orig)); } }