We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void insertionSort1(int n, List<Integer> arr) {
int cur = arr.get(n - 1);
int i = n - 1;
while (i >= 0) {
int next = (i != 0) ? arr.get(i - 1) : cur;
if (cur < next) {
arr.set(i, next);
System.out.println(arr.toString().replaceAll("[\\[\\],]", ""));
i--;
} else {
arr.set(i, cur);
break;
}
}
System.out.println(arr.toString().replaceAll("[\\[\\],]", ""));
}
Cookie support is required to access HackerRank
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 solution