public static void main(String[] args) {
int[] a1 = {5,4,3,2,1};
insertSort(a1);
System.out.println(Arrays.toString(a1));
}
private static void mpSort(int[] a) {
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a.length-i;j++) {
if(a[j]>a[j+1]) {
int temp = a[j];
a[j] = a[j+1];
a[j+1]= temp;
}
}
}
}
private static void selectSort(int[] a) {
for(int i=0;i<a.length;i++)
{
int k = i;
for(int j = i+1; j<a.length;j++) {
if(a[j]<a[k])
{
k = j;
}
}
if(k != i)
{
int temp = a[k];
a[k] = a[i];
a[i] = temp;
}
}
}
public static void insertSort(int[] a) {
for(int i = 0; i<a.length-1; i++)
{
for(int j = i+1; j > 0;j--)
{
if(a[j]<a[j-1]) {
int temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
}
private static void insertSort(int[] a) {
int i , j;
for( i = 1;i<a.length;i++) {
for( j = i-1;j>=0;j--) {
if(a[i]<a[j]) {
break;
}
}
if(j!=i-1) {
int temp = a[i];
for(int k = i-1;k>=0;k--) {
a[k+1] = a[k];
}
a[j+1] = temp;
}
}}
}