You are viewing a single comment's thread. Return to all comments →
my Java 8 solution:
public static void insertionSort2(int n, List<Integer> arr) { for (int i=1; i < n; i++) { for (int j=0; j < i; j++) { if (arr.get(i) < arr.get(j)) { int toInsert = arr.remove(i); arr.add(j, toInsert); } } StringBuilder sb = new StringBuilder(); arr.forEach(item -> sb.append(item + " ")); System.out.println(sb.toString().trim()); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 2
You are viewing a single comment's thread. Return to all comments →
my Java 8 solution: