You are viewing a single comment's thread. Return to all comments →
JS solution
function processData(input) { var input = input.split('\n'); var elements = input[1].split(' ') for(i = 0; i < elements.length; i++){ input[i] = +input[i]; } var i = elements.length - 2; var e = elements[elements.length - 1]; while (i >= 0 && e <= elements[i]){ elements[i+1] = elements[i]; console.log(elements.join(' ')); i--; } elements[i+1] = e; console.log(elements.join(' ')); }
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 →
JS solution