You are viewing a single comment's thread. Return to all comments →
JAVA 8 public static void insertionSort1(int n, List arr) { // Write your code here int key=arr.get((arr.size()-1)); for(int i=arr.size()-1;i>=0;i--){ if((i-1)<0){ arr.set(0,key); for(int j:arr){ System.out.print(j+" "); } } else if((arr.get(i-1)>=0)&& arr.get(i-1)>key){ arr.set(i,arr.get(i-1)); for(int j:arr){ System.out.print(j+" ");
} System.out.println(); } else if((arr.get(i-1)>=0)&&arr.get(i-1)<key){ arr.set(i,key); for(int j:arr){ System.out.print(j+" "); } break; } } } }
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 →
JAVA 8 public static void insertionSort1(int n, List arr) { // Write your code here int key=arr.get((arr.size()-1)); for(int i=arr.size()-1;i>=0;i--){ if((i-1)<0){ arr.set(0,key); for(int j:arr){ System.out.print(j+" "); } } else if((arr.get(i-1)>=0)&& arr.get(i-1)>key){ arr.set(i,arr.get(i-1)); for(int j:arr){ System.out.print(j+" ");