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.
@ilmash it's a great problem as it explains the essence of insertion sort.
In insertion sort you assume the array upto some i is sorted and then insert the ith element.
Here's from wikipedia
for i = 1 to length(A) - 1
x = A[i]
j = i
while j > 0 and A[j-1] > x
A[j] = A[j-1]
j = j - 1
A[j] = x
In this challenge you are only performing the final iteration of i = n-1
Given a sorted list with an unsorted number V in the right-most cell, can you write some simple code to insert V into the array so it remains sorted?
And by printing each time you ensure that you have understood the swap properly :)
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
@ilmash it's a great problem as it explains the essence of insertion sort.
In insertion sort you assume the array upto some i is sorted and then insert the ith element.
Here's from wikipedia
In this challenge you are only performing the final iteration of i = n-1
Given a sorted list with an unsorted number V in the right-most cell, can you write some simple code to insert V into the array so it remains sorted?
And by printing each time you ensure that you have understood the swap properly :)
Good luck