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.
Insertion Sort - Part 1
Insertion Sort - Part 1
Sort by
recency
|
864 Discussions
|
Please Login in order to post a comment
Python 3
Here is the code, as brute as I possible could:
int key=arr.get(n-1); for(int i=n-1;i>=0;i--) { if(i-1>=0 && arr.get(i-1)>=key ) { arr.set(i,arr.get(i-1)); for(int a:arr) System.out.print(a+" "); } else { arr.set(i,key); for(int a:arr) System.out.print(a+" "); break; } System.out.println(); }
My solution in C:
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
Simple Javascript solution which follows the description: