sort nearly sorted array