A simple program that I wrote using JavaScript to show the concept of Shell Sort algorithm.
If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Program Listing
If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
<html>
<head>
<title>Shell Sort</title>
</head>
<body>
<script>
var values=[],a=[];
var temp=0,pos=0;
document.write("<font face='arial' size='4'>SHELL SORT </font>");
document.write("<br><br>");
for (a=0; a<10; a++) {
values.push(Number(prompt("Enter item value at no. " + (a+1))));
}
document.write("<font face='arial' size='4'>Numbers");
document.write(" given by the user </font>");
document.write("<br><br>");
for (a=0;a<10; a++) {
document.write("<font face='arial' size='4'> " +values[a] + "");
}
function shellSort (a) {
for (var h = a.length; h = parseInt(h / 2);) {
for (var i = h; i < a.length; i++) {
var k = a[i];
for (var j = i; j >= h && k < a[j - h]; j -= h)
a[j] = a[j - h];
a[j] = k;
}
}
return a;
}
shellSort(values);
document.write("<br><br>");
document.write("<font face='arial' size='4'>Sorted List of Numbers </font>");
document.write("<br><br>");
for (a=0; a<10; a++) {
document.write("<font face='arial' size='4'> " + values[a]+"</font>");
}
</script>
</body>
</html>
No comments:
Post a Comment