1. Bubble Sort In each loop, place the largest number on the top, creating a “bubble”
const bubbleSort = (arr) => { for (let i = arr.length - 1; i > 0; i--) { let swap = false; for (let j = 0; j < i; j++) { if(arr[j] > arr[j + 1]) { let temp = arr[j + 1]; arr[j + 1] = arr[j]; arr[j] = temp; swap = true; } } if(!
Sorting and Locking Pairs for Tideman (CS50 Problem Set 3) The Original Problem Explained (Tideman) The Problem Encountered Although with the test sets provided with the example seemed to work just fine with the code I originally wrote, when graded, it showed that my code didn’t lock the pairs correctly (meaning it didn’t lock what it was supposed to, and locked pairs where it should have skipped).
1. Sorting Problem Instructions