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.
staticvoidinsertionSort1(intn,int[]arr){// Complete this functionbooleanisInserted=false;intunsortedval=-1;intunsortedindex=-1;for(inti=arr.length-1;i>0;i--){if(arr[i]<arr[i-1]){unsortedval=arr[i];unsortedindex=i;break;}}for(inti=unsortedindex;i>=0;i--){if(i>0&&arr[i-1]>=unsortedval){arr[i]=arr[i-1];}else{arr[i]=unsortedval;isInserted=true;}for(intj=0;j<arr.length;j++){System.out.print(arr[j]+" ");}System.out.print("\n");if(isInserted)break;}}
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 →
-