[Lab Task HTML/JAVASCRIPT]
Please read 10 numbers that are list below, sort the numbers and then print those numbers.
10 numbers = { 9, 3, 2, 1, 10, 30, 4, 6, 7, 8}
Output should have a sorted list
[Reference JavaScript code]
<html>
<body>
<H1>prompt()</h1>
<p id="pro"></p>
<script>
// Array creation
var num= new Array();
var ix = 0;
// Read 10 numbers
for (ix = 0; ix < 10; ix++)
{num[ix] = prompt("Enter a number");
}
// Write 10 numbers
document.writeln( num + "<br>");
// Write 10 numbers one by one
for(ix = 0; ix < 10; ix++)
{
document.writeln( num[ix] + "<br>");
}
</script>
</body>
</html>
[Insertion Sort in pseudocode] [What should be the java code in order to sort]
i ← 1
while i < 10
j ← i
while j > 0 and num[j-1] > num[j]
swap A[j] and A[j-1]
j ← j - 1
end while
i ← i + 1
end while
{WHAT I AM STUCK ON / INCOMPLETE CODE FROM PSEUDOCODE}
var i; var j; var temp; i = 1; while (i< 10) { j = i; while (j > 10 && num[j-1] < num[j]) {
<html> <body> <H1>prompt()</h1> <p id="pro"></p> <script> // Array creation var num = new Array(); var ix = 0; // Read 10 numbers for (ix = 0; ix < 10; ix++) { num[ix] = prompt("Enter a number"); } // Write 10 numbers document.writeln(num + "<br>"); // Write 10 numbers one by one for (ix = 0; ix < 10; ix++) { document.writeln(num[ix] + "<br>"); } var i = 1; while (i < 10) { var j = i; while (j > 0 && num[j - 1] > num[j]) { var temp = num[j]; num[j] = num[j - 1]; num[j - 1] = temp; j--; } i++; } // Write 10 numbers document.writeln(num + "<br>"); // Write 10 numbers one by one for (ix = 0; ix < 10; ix++) { document.writeln(num[ix] + "<br>"); } </script> </body> </html>
Get Answers For Free
Most questions answered within 1 hours.