Generic InsertionSort implementation.