Question: How would I write the insertion sort algorithm to work with the rest of the code instead of the sort function on this piece of
How would I write the insertion sort algorithm to work with the rest of the code instead of the sort function on this piece of javascript. var list ;
var sortedList ;
function populateList
list ;
for let i ; i ; i
list.pushrandomString;
displayListlist 'listSection';
function randomString
return Math.randomtoStringsubstring;
function displayListarr elementId
document.getElementByIdelementIdtextContent arr.join;
function sortList
sortedList list;
sortedList.sort;
displayListsortedList 'sortedListSection';
Insertion Sort implementation
function insertionSortinputArr
var n inputArr.length;
for let i ; i n; i
Choosing the first element in our unsorted subarray
var current inputArri;
The last element of our sorted subarray
var j i ;
while j && current inputArrj
inputArrj inputArrj;
j;
inputArrj current;
return inputArr;
function insertValue
var value document.getElementByIdinsertValuevalue;
if valuetrim
alertPlease enter a value.;
return;
sortedList.pushvalue;
sortedList.sort;
displayListsortedList 'sortedListSection';
function randomizeList
populateList;
document.getElementByIdsortedListSectiontextContent ;
populateList;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
