Sort instances by number in increasing or decreasing order