Bubble sort is a sorting technique which sort by swapping the nearest values
Time Comp
const bubbleSort=(arr)=>{
let n=arr.length
for(let i=0;i<n;i++)
{
for(let j=0;j<n-i-1;j++)
{
if(arr[j] > arr[j+1])
{
[arr[j],arr[j+1]] = [arr[j+1],arr[j]]
}
}
}
return arr
}
console.log(bubbleSort([1,34,45,54,12,35,45,29,10,14,16]))
Top comments (0)