sort an almost-sorted array