Sort after adding elements to an array.