function bubbleSort(arr){
let len = arr.length;
let cost = 0;
for(let i=0; i<len; i++){
for(let j=0; j<len-1; j++){
if(arr[j] > arr[j+1]){
swap(arr, j, j+1);
}
}
}
return arr
}
let unsortedArr = [0, 5, 6, 8, 2, 1, 3, 7, 4, 10, 12, 11]
console.log(bubbleSort(unsortedArr))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter