Insertion Sort in Java
package code.example.basic; public class InsertationSortExample { public static void main(String args[]){ int ar[]={4,5,6,7,3,4,2}; for(int i=1;i<ar.length;i++){ for(int j=0;j<=i;j++){ if(ar[j]>ar[i]){ ar[j]= ar[j]+ar[i]-(ar[i]=ar[j]); } } for(int k=0;k<ar.length;k++){ System.out.print(ar[k]); } System.out.println("-"); } for(int i=0;i<ar.length;i++){ System.out.println(ar[i]); } } }
post a comment