Skip to content

Commit a9ef685

Browse files
author
highflyer910
committed
Bubblesort
1 parent 0d2d9f3 commit a9ef685

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

bubblesort.js

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

0 commit comments

Comments
 (0)