Please use jsfiddle!!! You will need to fork your JSFiddle for your List into a
ID: 3937016 • Letter: P
Question
Please use jsfiddle!!! You will need to fork your JSFiddle for your List into a new Fiddle. In this Fiddle we are going to add sorting functions. This is a great time to clean up your list with things that you have learned. You should automatically populate the List with 20 element (random strings). Once you have completed this - you will add 2 sort functions you can use any sort method that you desire for each of the sort functions. You can also delineate the functions by the name of the Sort function - so your functions might be QuickSort() and MergeSort() - if you chose to implement those 2 algorithms (you can select from any sort functions). The interface should have buttons to (1) Repopulate the list with Random strings. (2) Sort list with selected algorithm 1 (3) Sort list with selected algorithm 2 and (4) Insert a new random string entered by the user into the list. After each operation it should display the new list. The option 4 here will insert the new string entered by the user (you will need a check box) in the correct sorted position and you should print the new list with the new element on the screen. Quiz Do quiz on sorting - http://geeksquiz.com/algorithms/searching-and-sorting/Assignment Grading - Creating a random string array is worth 1 point. Each sort algorithm is worth 3 points, and the insertion is worth 3 points.Explanation / Answer
HTML part code::::
<button>Repopulate the list with randome String algorithm</button>
<button>Sort list with QuickSort algorithm</button>
<span id="quicklist"></span>
<button>Sort list with QuickSort algorithm</button>
<span id="mergelist"></span>
<button>Insert new list byuser</button>
<span id="userlist"></span>
Javascript Part:::
var numbers = [5, 15, 14, 1, -6, 26, -100, 0, 99];
fillrandomStrings(){
var arr = []
while(arr.length < 8){
var randomnumber = Math.ceil(Math.random()*100)
if(arr.indexOf(randomnumber) > -1) continue;
arr[arr.length] = randomnumber;
}
var newar=mergeSort(arr);
document.getElementbyId("usergivenlist").html(newar);
}
function mergeSort (numbers) {
if (arr.length < 2) return numbers;
var mid = Math.floor(numbers.length /2);
var subLeft = mergeSort(numbers.slice(0,mid));
var subRight = mergeSort(numbers.slice(mid));
var aar= merge(subLeft, subRight);
document.getElementbyId("mergesortlist").html(aar);
}
function merge (a,b) {
var result = [];
while (a.length >0 && b.length >0)
result.push(a[0] < b[0]? a.shift() : b.shift());
return result.concat(a.length? a : b);
}
function quicklist(){
var bar= quickSort();
document.getElementbyId("mergesortlist").html(bar);
}
function quickSort() {
if (indexLow == undefined) indexLow = 0;
if (indexHigh == undefined) indexHigh = numbers.length - 1;
var i = indexLow;
var j = indexHigh;
var pivot = numbers[indexLow + Math.floor((indexHigh - indexLow) / 2)];
while (i <= j) {
while (numbers[i] < pivot) {
i++;
}
while (numbers[j] > pivot) {
j--;
}
if (i <= j) {
var swap = numbers[i];
numbers[i] = numbers[j];
numbers[j] = swap;
i++;
j--;
}
}
if (indexLow < j) {
quickSort(numbers, indexLow, j);
}
if (i < indexHigh) {
quickSort(numbers, i, indexHigh);
}
}