cpp implementation of Insert Interval