import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] arr={1,4,2,7,5,9,-2};
insertSort(arr);
System.out.println(Arrays.toString(arr));
}
public static void insertSort(int[] arr){
for(int i=1;i<arr.length;i++){
int insertIndex=i;
int insertValue=arr[i];
while(insertIndex>0&&insertValue<arr[insertIndex-1]){
arr[insertIndex]=arr[insertIndex-1];
insertIndex--;
}
arr[insertIndex]=insertValue;
}
}
}