Skip to content

Commit f87a4f5

Browse files
committed
BubbleSort
1 parent 5614404 commit f87a4f5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎SortingAlgorithms/BubbleSort.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Language: Javascript
2+
//Author: Tran Lan Anh
3+
//Github: https://github.com/Lanhbao
4+
5+
function bubleSort(arr){
6+
for(let i = arr.length-1; i > 0; i--){
7+
for(let j = 0; j < i; j++){
8+
if(arr[j] >= arr[j+1]){
9+
let temp = arr[j];
10+
arr[j]=arr[j+1];
11+
arr[j+1]=temp;
12+
}
13+
}
14+
}
15+
return arr;
16+
}
17+
//test
18+
var arr = [5,2,3,9,0];
19+
bubleSort(arr);
20+
21+
22+

0 commit comments

Comments
 (0)