Skip to content

Commit 5773c5d

Browse files
committed
Add Bubble Sort Problem
1 parent f9c7560 commit 5773c5d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

L-I/0008 BubbleSort/BubbleSort.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const BubbleSort = (arr) => {
2+
for (let i = 0; i < arr.length - 1; i++) {
3+
for (let j = 0; j < arr.length - i - 1; j++) {
4+
if (arr[j] > arr[j + 1]) {
5+
temp = arr[j];
6+
arr[j] = arr[j + 1];
7+
arr[j + 1] = temp;
8+
}
9+
}
10+
}
11+
};
12+
13+
arr = [0, 4, 2, 3, 7, 3, 6, 2, 9, 10, 2, 6];
14+
arrOne = [45, 32, 12, 67, 86, 92, 29, 24, 53, 1, 6, 32, 56];
15+
16+
BubbleSort(arr);
17+
BubbleSort(arrOne);
18+
19+
console.log(arr);
20+
console.log(arrOne);

0 commit comments

Comments
 (0)