You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
public static void insertionSortPart2(int[] ar) { for( int i = 1; i<ar.length; i++) { int unsorted = ar[i]; for( int j = i-1;j>=0; j-- ) { if(unsorted< ar[j]) ar[j+1] = ar[j]; else if (ar[j] <= unsorted) { ar[j+1] = unsorted; break; } if( j == 0 && unsorted<ar[0]) ar[0] = unsorted; } printArray(ar); } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int s = in.nextInt(); int[] ar = new int[s]; for(int i=0;i<s;i++){ ar[i]=in.nextInt(); } insertionSortPart2(ar); } private static void printArray(int[] ar) { for(int n: ar){ System.out.print(n+" "); } System.out.println("");
} }
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 →
import java.io.; import java.util.;
public class Solution {
} }