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 0551dba

Browse files
committed
remove changes made on adding alternative implementation of bubble sort
1 parent 6de559d commit 0551dba

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

‎Sorts/bubblesort.js‎

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,4 @@ bubbleSort(ar);
2828
//Array after sort
2929
console.log(ar);
3030

31-
/*alternative implementation of bubble sort algorithm.
32-
Using a while loop instead. For educational purposses only
33-
*/
34-
/*
35-
*In bubble sort, we keep iterating while something was swapped in
36-
*the previous inner-loop iteration. By swapped I mean, in the
37-
*inner loop iteration, we check each number if the number proceeding
38-
*it is greater than itself, if so we swap them.
39-
*/
40-
41-
function bubbleSort(arr){
42-
var swapped = true;
43-
while(swapped){
44-
var swapped = false;
45-
for(var i = 0; i < arr.length; i++){
46-
if(arr[i] > arr[i + 1]){
47-
var temp = arr[i];
48-
arr[i] = arr[i + 1];
49-
arr[i + 1] = temp;
50-
swapped = true;
51-
}
52-
}
53-
}
54-
return arr;
55-
}
56-
57-
//test
58-
console.log("-----before sorting-----")
59-
var array = [10,5,3,8,2,6,4,7,9,1];
60-
console.log(array);
61-
console.log("-----after sorting-----")
62-
console.log(bubbleSort(array));
63-
6431

0 commit comments

Comments
(0)

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