See the overloaded qSort function here. You will obviously have to sort twice so you need to define one function comparing the x values and another comparing the y values.