Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bubble Sort Algorithm implemented in JS
- function sort(arr){
- let isSorted = false;
- let end = arr.length - 1;
- while (!isSorted) {
- isSorted = true;
- for (let i = 0; i < end; i++){
- if (arr[i] > arr[i + 1]){
- isSorted = false;
- swap(arr, i, i + 1);
- }
- }
- end--;
- }
- }
- function swap(arr, a, b){
- let temp = arr[a];
- arr[a] = arr[b];
- arr[b] = temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement