modifed insertion_sort so that it can output an array of the carried indices