This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
export function bubbleSort (list, comparator) {
let upperIndex = list.length - 1;
while (upperIndex > 0) {
let swapIndex = 0;
for (let i = 0; i < upperIndex; i += 1) {
if (comparator(list[i], list[i + 1]) > 0) {
const temp = list[i + 1];
list[i + 1] = list[i];
list[i] = temp;
swapIndex = i;
}
}
upperIndex = swapIndex;
}
return list;
}