working example
https://stackblitz.com/edit/js-faixur
code :-
https://stackblitz.com/edit/js-faixur
code :-
function swap(myArray,to,from)
{
var temp=myArray[to];
myArray[to]= myArray[from];
myArray[from]=temp;
}
function BubbleSort(arr)
{
for(let i=0;i<arr.length;i++)
{
for(let x=0;x<arr.length-1;x++)
{
if(arr[x]<arr[x+1])
{
swap(myArray,(x),x+1);
}
}
}
}
var myArray=[];
for(var i=0;i<20;i++)
{
myArray.push( Math.round(Math.random()*1000));
}
console.time();
BubbleSort(myArray);
console.log(myArray);
console.timeEnd();
Comments
Post a Comment