Skip to content

Commit adaa123

Browse files
committed
worked on bubble sorting algorithm
1 parent 5614404 commit adaa123

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎SortingAlgorithms/bubblesort.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Language: Javascript
2+
//Author: Sarah Sakhri
3+
//Github: https://github.com/sarahsakhri
4+
5+
let x = [22, 35, 40, 5, 777, 8, 9, 9, 223, 46, 34];
6+
7+
console.log("---- Original array -----");
8+
console.log(x);
9+
10+
function bubbleSort(array) {
11+
12+
for (let i = 0; i < array.length; i++) {
13+
14+
for (let j = 0; j < (array.length - i - 1); j++) {
15+
16+
if (array[j] > array[j + 1]) {
17+
18+
let temp = array[j];
19+
array[j] = array[j + 1];
20+
array[j + 1] = temp;
21+
}
22+
}
23+
}
24+
}
25+
26+
bubbleSort(x);
27+
28+
console.log("---- Bubble sorted array -----");
29+
console.log(x);

0 commit comments

Comments
 (0)