You are viewing a single comment's thread. Return to all comments →
int key=arr.get(n-1); for(int i=n-1;i>=0;i--) { if(i-1>=0 && arr.get(i-1)>=key ) { arr.set(i,arr.get(i-1)); for(int a:arr) System.out.print(a+" "); } else { arr.set(i,key); for(int a:arr) System.out.print(a+" "); break; } System.out.println(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
int key=arr.get(n-1); for(int i=n-1;i>=0;i--) { if(i-1>=0 && arr.get(i-1)>=key ) { arr.set(i,arr.get(i-1)); for(int a:arr) System.out.print(a+" "); } else { arr.set(i,key); for(int a:arr) System.out.print(a+" "); break; } System.out.println(); }