@@ -0,0 +1,2223 @@
+package algorithms.sorting;%0D%0A%0D%0Aimport java.util.Scanner;%0D%0A%0D%0A/*%0D%0A * Insert element into sorted list:%0D%0A * Given a sorted list with an unsorted number V in the rightmost cell, can you%0D%0A * write some simple code to insert V into the array so that it remains sorted?%0D%0A * %0D%0A * Print the array every time a value is shifted in the array until the array is%0D%0A * fully sorted. The goal of this challenge is to follow the correct order of%0D%0A * insertion sort.%0D%0A * %0D%0A * Guideline: You can copy the value of V to a variable and consider its cell%0D%0A * %22empty%22. Since this leaves an extra cell empty on the right, you can shift%0D%0A * everything over until V can be inserted. This will create a duplicate of each%0D%0A * value, but when you reach the right spot, you can replace it with V.%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 - the sorted array of integers%0D%0A * Output Format%0D%0A * On each line, output the entire array every time an item is shifted in it.%0D%0A * %0D%0A * Constraints:%0D%0A * 1 %3C= s %3C= 1000%0D%0A * -10000 %3C= V %3C= 10000,V is an element of ar%0D%0A * %0D%0A * Sample Input:%0D%0A * 5%0D%0A * 2 4 6 8 3%0D%0A * %0D%0A * Sample Output:%0D%0A * 2 4 6 8 8%0D%0A * 2 4 6 6 8%0D%0A * 2 4 4 6 8%0D%0A * 2 3 4 6 8%0D%0A */%0D%0Apublic class InsertionSortPartOne %7B%0D%0A%0D%0A%09public static void insertIntoSorted(int%5B%5D ar) %7B%0D%0A%09%09for (int top = 1; top %3C ar.length; top++) %7B%0D%0A%09%09%09int temp = ar%5Btop%5D;  // copy that item into temp variable%0D%0A%09%09%09int pos = top - 1;%0D%0A%09%09%09while (pos %3E= 0 && ar%5Bpos%5D %3E temp) %7B%0D%0A%09%09%09%09// move items that are bigger than temp up one position%0D%0A%09%09%09%09ar%5Bpos+1%5D = ar%5Bpos%5D;%0D%0A%09%09%09%09pos--;%0D%0A                printArray(ar);%0D%0A%09%09%09%7D%0D%0A%09%09%09ar%5Bpos + 1%5D = temp;  // place temp into last vacated position%0D%0A%09%09%7D%0D%0A        printArray(ar);%0D%0A%09%7D%0D%0A    %0D%0A    %0D%0A/* Tail starts here */%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         insertIntoSorted(ar);%0D%0A         in.close();%0D%0A    %7D%0D%0A    %0D%0A    %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    %0D%0A    %0D%0A%7D

Add InsertionSortPartOne