You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

30 lines
571 B

/**
*
*/
var Bubblesort = function() {
this.instructions = [];
};
Bubblesort.prototype = Object.create(Sorter.prototype);
/**
*
*/
Bubblesort.prototype.sort = function(arr) {
var i;
var swapped = false;
var len = arr.length;
// NOTE this starts at the beginning of the array each time
for (i = 1; i < len; i++) {
if (arr[i - 1].value > arr[i].value) {
this.swap(arr, i, i - 1);
swapped = true;
console.log(dump(arr));
}
}
if (swapped === true) {
this.sort(arr);
}
};