Wouldn't it be much easier to keep children in a priority queue and just take the first?