Question: Please read 10 numbers that are list below, sort the numbers and then print those numbers. 10 numbers = { 9, 3, 2, 1, 10,
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}
[Reference JavaScript code]
prompt()
// 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 + " ");
// Write 10 numbers one by one
for(ix = 0; ix < 10; ix++)
{
document.writeln( num[ix] + " ");
}
[Insertion Sort in pseudocode]
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
[JavaScript code]
[output]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
