You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
551 B
JavaScript

function bubble_Sort(a)
{
var swapp;
var n = a.length-1;
var x=a;
do {
swapp = false;
for (var i=0; i < n; i++)
{
if (x[i] < x[i+1])
{
var temp = x[i];
x[i] = x[i+1];
x[i+1] = temp;
swapp = true;
}
}
n--;
} while (swapp);
return x;
}
console.log(bubble_Sort([12, 345, 4, 546, 122, 84, 98, 64, 9, 1, 3223, 455, 23, 234, 213]));