Click here to Skip to main content
15,029,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<html>
<head>
<script language="javascript">
function bubble()
{
var a=new array();
var b=new array();
var temp;
b=prompt("enter values","0");
a=b.split(",");
for(i=0;i<=9;i++)
  {
  for(j=i+1;j<=9;j++)
     {
       temp=a[i];
       a[i]=a[j];
       a[j]=temp;
     }
   }
for(i=0;i<=9;i++)
   {
       alert(a[i]);
   }
       
}
bubble();
</script>
</head>
</html>
Posted
Updated 28-Sep-11 17:57pm
v2

1 solution

You missed the main condition part. :doh:
JavaScript
if(a[j]>a[j+1])
{
    temp=a[j+1];
    a[j+1]=a[j];
    a[j]=temp;
}


Ref:http://www.metalshell.com/source_code/112/Javascript_Bubble_Sort.html[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900