Question

In: Computer Science

**Need HTML and Javacript** You will need to fork your JSFiddle for your List into a...

**Need HTML and Javacript**

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.

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

HTML part:

<button id="bRandom">
Create Randomized String List
</button>
<button id="bIns">
Insertion Sort
</button>
<button id="bQuick">
Quick Sort
</button><hr/>
<button id="bnString">
Insert new string
</button>
<input type="text" id="newString" placeholder="Enter String">
<hr>
<textarea id="listArea" cols = "50" rows="20"></textarea>

Javascript:

bQuick = document.getElementById("bQuick");

bIns = document.getElementById("bIns");

bRand = document.getElementById("bRandom");

bnString = document.getElementById("bnString");

newString = document.getElementById("newString");

//adding event listeners

bRand.addEventListener("click", createList);

bQuick.addEventListener("click", sortQuick);

bIns.addEventListener("click", sortIns);

bnString.addEventListener("click", insertNew);

//list storage

var list = [];

function createList(){  

list = [];

//populating list

for(i=0;i<20;i++){

var str = Math.random().toString(36).substring(10);

list.push(str);

}

updateVisual();  

}

function updateVisual(){

//update text area

var data="";

for(i=0;i<list.length;i++){

data += list[i] + "\n";

}

  

document.getElementById("listArea").value = data;

}

function sortQuick(){

Quick.sort(list);

updateVisual();

}

function sortIns(){

insertionSort(list);

updateVisual();

}

function insertNew(){

list.push(newString.value);

sortQuick();

}

function insertionSort(array)

{

for(var i = 1; i < array.length; ++i)

{

var item = array[i];

for(var j = i - 1; j >= 0; --j)

{

if(array[j] <= item) break;

array[j + 1] = array[j];

}

array[j + 1] = item;

}

return array;

}

var Quick= (function() {

function swap(array, indexA, indexB) {

var temp = array[indexA];

array[indexA] = array[indexB];

array[indexB] = temp;

}

function partition(array, pivot, left, right) {

var storeIndex = left,

pivotValue = array[pivot];

swap(array, pivot, right);

for(var v = left; v < right; v++) {

if(array[v] < pivotValue) {

swap(array, v, storeIndex);

storeIndex++;

}

}

swap(array, right, storeIndex);

return storeIndex;

}

function sort(array, left, right) {

var pivot = null;

if(typeof left !== 'number') {

left = 0;

}

if(typeof right !== 'number') {

right = array.length - 1;

}

if(left < right) {

  

pivot = left + Math.ceil((right - left) * 0.5);

newPivot = partition(array, pivot, left, right);

sort(array, left, newPivot - 1);

sort(array, newPivot + 1, right);

}

}

return {

sort: sort

};

}();


SAMPLE OUTPUT:


Related Solutions

For this assignment you need to create a ToDo list using Javascript, along with HTML and...
For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link in CSS from a...
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link in CSS from a...
Write a C or C++ program using the fork() system call function. You will need to...
Write a C or C++ program using the fork() system call function. You will need to create 3 processes – each process will perform a simple task. Firstly, create an integer "counter" initialized to a random value between 1 and 100. Print this number to the console. This can be done by: Including the stdio.h and stdlib.h libraries Using the rand() function to generate your randomly generated number The main thread consists of the parent process. Your job is to...
List all the steps that you as the project manager and your team will need to...
List all the steps that you as the project manager and your team will need to complete to get the CRM system developed and operational. The steps will include all the processes that must be accomplished as well as the subprocesses. Create a WBS to include the activities needed to implement a CRM system Explain the need and value for each task
You have a tuning fork, called tuning fork A of unknown frequency. you know that when...
You have a tuning fork, called tuning fork A of unknown frequency. you know that when it vibrates, it has a maximum amplitude of 0.002ft. Tuning fork B, which has a period of 0.05s causes tuning for A to vibrate with an amplitude of 0.01ft. Tuning for C which has a period of 0.2s causes tuning fork A to vibrate with an amplitude of 0.015ft. What is the natural frequency of tuning fork A?
Look at the HTML below ( do NOT modify the HTML), Outer paragraph, outer list, div...
Look at the HTML below ( do NOT modify the HTML), Outer paragraph, outer list, div with 2 inner paragraphs and one inner list , create a CSS which will: Make the outer list text color blue , and make the outer (non div) paragraph blue, and the div inner list element pink also inside the div element make the first inner paragraph green, and in the div element the second paragraph blue, so that in order: blue-blue-green-blue-pink As a...
Given the HTML below ( do not modify the HTML), Outer paragraph, outer list, div with...
Given the HTML below ( do not modify the HTML), Outer paragraph, outer list, div with 2 inner paragraphs and one inner list , create a CSS which will: a) Make the outer list text color blue , and make the outer (non div) paragraph blue, and the div inner list element pink also inside the div element make the first inner paragraph green, and in the div element the second paragraph blue, so that in order: blue-blue-green-blue-pink b)As a...
Using brackets you will need to create the HTML page and CSS style sheet for the...
Using brackets you will need to create the HTML page and CSS style sheet for the given Form example. Form 1: create an HTML page with a form that contains a text input field. The label for the text field should be “City”. Beneath it should be a submit button “Lookup”. Place a horizontal line beneath the Lookup button and add three radio buttons labeled “Beginner”, “Intermediate”, and “Advanced”. Your page should have a title and a header in the...
<!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- -->...
<!DOCTYPE html> <html> <body> <!-- replace the text below with your name!--> <!-- --> <!-- --> <title> TYPE YOUR NAME HERE</title> <script> // // A bug collector collects bugs every day for five days. Write a function that keeps // a running total of the number of bugs collected during the five days. The loop // should ask for the number of bugs collected for each day, and when the loop is // finished, the program should display the total...
List the route of "Sally" sugar molecule from the pasta on a fork to its providing...
List the route of "Sally" sugar molecule from the pasta on a fork to its providing nutrition to the cardiac muscle. This is JUST a list of structures [from the mouth to where the food is absorbed into the blood to the muscle]. Be complete.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT