The thing I was looking for is caled the 'in-order successor' algorithm.