split ( p : like first_place; before, after : BOX [ like Current ] ) is require nonvoid : p /= Void and before /= Void and after /= Void local q, r, s : like first_place rnk, next_rnk : INTEGER low, high, subtree : like Current left, right : like first_place p_less, next_p_less : BOOLEAN do -- Not all these local veriables are used. They -- should suggest what's needed for the correct version. -- Caution: in the proper version, the red-black ranks -- of various nodes need to be calculated `on the fly.' -- This is where one needs to be careful. from !! low.make -- create an empty tree to contain -- all nodes left of p (in inorder) !! high.make q := first_place -- the leftmost node in the tree remove_first -- removes the leftmost node from the tree q.unlink -- resets fields in q to Void to avoid -- `dangling pointers.' Otherwise it -- will violate the requirements for the attach -- feature. until q = p loop -- transfer node q from Current tree to low low.attach_last (q) q := first_place remove_first q.unlink end -- At this point, all nodes to the left of -- p have been transferred to the tree low. -- Note that p itself has been removed from -- the front of the list, so the remaining nodes -- are those to the right of p in the original tree. !! high . make_with_root ( root, protecting, rb_rank ) -- It is necessary to remove all connection to -- this tree in the Current tree -- a node -- can belong to only one tree. Therefore wipe_out -- Put the low and high trees in the boxes -- before and after respectively. before.put ( low ) after.put ( high ) end