diff --git a/Algorithms/bubbleSort.js b/Algorithms/bubbleSort.js new file mode 100644 index 0000000000..b2ae08178a --- /dev/null +++ b/Algorithms/bubbleSort.js @@ -0,0 +1,20 @@ +var a = [33, 103, 3, 726, 200, 984, 198, 764, 9]; + +function bubbleSort(a) +{ + var swapped; + do { + swapped = false; + for (var i=0; i < a.length-1; i++) { + if (a[i] > a[i+1]) { + var temp = a[i]; + a[i] = a[i+1]; + a[i+1] = temp; + swapped = true; + } + } + } while (swapped); +} + +bubbleSort(a); +console.log(a);