Tuesday, 14 May 2013
My own sorting-Below is sample program how to implement sorting
<html>
<script type="text/javascript">
var r=new Array();
r[0]=1;
r[1]=237654;
r[2]=99999;
r[3]=99;
r[4]=10000;
var b=new Array();
var t=0;
document.write("Given format"+r);
document.write("<br />")
for (i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
if (r[i]<=r[j])
{
t=t+1;
}
}
if (t==1)
{
b[4]=r[i];
document.write(" Highest no"+b[4]+"<br /> ");
}
else if(t==2)
{
b[3]=r[i];
document.write("second highest no"+b[3]+"<br /> ");
}
else if(t==3)
{
b[2]=r[i];
document.write("Third highest no"+b[2]+"<br /> ");
}
else if(t==4)
{
b[1]=r[i];
document.write("Fourth highest no"+b[1]+"<br /> ");
}
else if(t==5)
{
b[0]=r[i];
document.write("Least no"+b[0]+"<br /> ");
}
t=0;
}
document.write("Output in Ascending order:")
for(i=0;i<=4;i++)
{
document.write(b[i]+" ");
}
</script>
</html>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment