Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de0a0c2

Browse files
Bubble sort algorithm
1 parent 58f7848 commit de0a0c2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎Algorithm/bubbleSort.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function bubbleSort(arr) {
2+
for (let i = arr.length; i > 0; i--) {
3+
for (let j = 0; j < i; j++) {
4+
if (arr[j] > arr[j + 1]) {
5+
let temp = arr[j];
6+
arr[j] = arr[j + 1];
7+
arr[j + 1] = temp;
8+
}
9+
}
10+
}
11+
12+
return arr;
13+
}
14+
15+
bubbleSort([5, 3, 8, 2, 1, 4]); // [ 1, 2, 3, 4, 5, 8 ]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /