Created
October 10, 2022 06:17
-
-
Save OlegKorn/5bb717178e690b16c6976ed0ed2cd9d4 to your computer and use it in GitHub Desktop.
bubble sort JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bubbleSort() { | |
a = [33, 2, 3345, 34456456, 3, 3434, 41, 314, 34, 34445] | |
for (var i = 0; i < a.length; i++) { | |
var swapped = false | |
for (var j = 0; j < a.length - 1; j++) { | |
if (a[j] > a[j+1]) { | |
var temp | |
temp = a[j] | |
a[j] = a[j+1] | |
a[j+1] = temp | |
temp = null | |
swapped = true | |
} | |
} | |
if (!swapped) { | |
break | |
} | |
console.log(a) | |
} | |
} | |
bubbleSort() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment