programming-examples/js/Functions/Write a JavaScript function to apply Bubble Sort algorithm..js

23 lines
551 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
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]));