Skip to content

Commit ea62eef

Browse files
authored
Merge pull request vJechsmayr#36 from gane5hvarma/feature/bubble_sort
bubble sort implementation in javascript
2 parents 3096951 + 272424c commit ea62eef

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎SortingAlgorithms/bubblesort.js‎

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

0 commit comments

Comments
 (0)