@@ -0,0 +1,2417 @@
+package algorithms.sorting;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * In Insertion Sort Part 1, you sorted one element into an array. Using the%0D%0A * same approach repeatedly, can you sort an entire unsorted array?%0D%0A * %0D%0A * Guideline: You already can place an element into a sorted array. How can you%0D%0A * use that code to build up a sorted array, one element at a time? Note that in%0D%0A * the first step, when you consider an element with just the first element -%0D%0A * that is already %22sorted%22 since there's nothing to its left that is smaller.%0D%0A * %0D%0A * In this challenge, don't print every time you move an element. Instead, print%0D%0A * the array after each iteration of the insertion-sort, i.e., whenever the next%0D%0A * element is placed at its correct position.%0D%0A * %0D%0A * Since the array composed of just the first element is already %22sorted%22, begin%0D%0A * printing from the second element and on.%0D%0A * %0D%0A * Input Format:%0D%0A * There will be two lines of input:%0D%0A * %0D%0A * s - the size of the array%0D%0A * ar - a list of numbers that makes up the array%0D%0A * %0D%0A * Output Format:%0D%0A * On each line, output the entire array at every iteration.%0D%0A * %0D%0A * Constraints:%0D%0A * 1 %3C= s %3C= 1000%0D%0A * -10000 %3C= x %3C= 10000, x is an element of ar%0D%0A * %0D%0A * Sample Input: %0D%0A * 6%0D%0A * 1 4 3 5 6 2%0D%0A * %0D%0A * Sample Output: %0D%0A * 1 4 3 5 6 2%0D%0A * 1 3 4 5 6 2%0D%0A * 1 3 4 5 6 2%0D%0A * 1 3 4 5 6 2%0D%0A * 1 2 3 4 5 6%0D%0A */%0D%0Apublic class InsertionSortPartTwo %7B%0D%0A%0D%0A    public static void insertionSortPart2(int%5B%5D ar)%0D%0A    %7B       %0D%0A        int itemsSorted;%0D%0A        %0D%0A        for (itemsSorted = 1; itemsSorted %3C ar.length; itemsSorted++) %7B%0D%0A            int temp = ar%5BitemsSorted%5D;%0D%0A            int loc = itemsSorted - 1;%0D%0A            %0D%0A            while (loc %3E= 0 && ar%5Bloc%5D %3E temp) %7B%0D%0A                ar%5Bloc + 1%5D = ar%5Bloc%5D;%0D%0A                loc = loc - 1;%0D%0A            %7D%0D%0A            %0D%0A            ar%5Bloc + 1%5D = temp;%0D%0A            printArray(ar);%0D%0A        %7D%0D%0A    %7D  %0D%0A    %0D%0A    %0D%0A      %0D%0A    public static void main(String%5B%5D args) %7B%0D%0A       Scanner in = new Scanner(System.in);%0D%0A       int s = in.nextInt();%0D%0A       int%5B%5D ar = new int%5Bs%5D;%0D%0A       for(int i=0;i%3Cs;i++)%7B%0D%0A            ar%5Bi%5D=in.nextInt(); %0D%0A       %7D%0D%0A       insertionSortPart2(ar);%0D%0A       in.close();%0D%0A                    %0D%0A    %7D    %0D%0A    private static void printArray(int%5B%5D ar) %7B%0D%0A      for(int n: ar)%7B%0D%0A         System.out.print(n+%22 %22);%0D%0A      %7D%0D%0A        System.out.println(%22%22);%0D%0A   %7D%0D%0A%7D

Add InsertionSortPartTwo