Build a cartesian tree