Write a script for selection sort. - Code

Latest

programs

Friday, October 7, 2011

Write a script for selection sort.


AIM


Write a script for selection sort.


PROGRAM
---------------------------------------------------------------------------
<html>
<head>
<title> Sort
</title>
<script language="Javascript">
var b,i,j,temp;
var a;
a=[];
document.write("Enter array");
for(i=0;i<5;i++)
{
b=prompt("enter array element=","0");
a[i]=parseInt(b);
}
for(i=0;i<5;i++)
{
document.write("<br>"+a[i]);
}
document.write("<br>Sorted array is");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<5;i++)
{
document.write("<br>"+a[i]);
}
</script> </head></html>




OUTPUT
Enter array
4
2
5
Sorted array is
2
4
5

No comments:

Post a Comment