public class InsertionSort{
public int[] insertionSort(int[] s){
int n = s.length;
int val;
int j;
for(int i = 1; i < n; i++){
val = s[i];
j = i - 1;
while((j >= 0) && (val < s[j])){
s[j + 1] = s[j];
j--;
}
s[j + 1] = val;
}
return s;
}
public void display(int[] s){
for(int i = 0; i < s.length; i++){
System.out.print(s[i] + " ");
}
System.out.println();
}
public static void main(String[] args){
InsertionSort s = new InsertionSort();
s.display(s.insertionSort(new int[]{8, 13, 20, 27, 16}));
}
}