
Bubble Sort
Bubble Sort implementation wth O(n^2) complexity based on JavaScript Algorithms.
Bubble sort is a simple sorting algorithm that repeatedly steps through the list to be sorted,
compares each pair of adjacent items and swaps them if they are in the wrong order.
Install
$ npm install --save bubblesort
Usage
var bubblesort = require('bubblesort');
bubblesort([3,1,4,1,5,9,2,6,5,4]);
bubblesort([9,2,8,6,1,3]);
bubblesort([5,2,4,6,1,3]);
function comparator(a, b) { return b - a; }
bubblesort([5,2,2,6,1,3], comparator);
bubblesort([0,0,0,0,0,-1], comparator);
var people = [
{name: 'Sindre', age: 30, place: 2},
{name: 'Passy', age: 25, place: 1},
{name: 'Stephen', age: 40, place: 4},
{name: 'Matt', age: 35, place: 3}
];
function comparePeople(a, b) { return a.age - b.age };
bubblesort(people, comparePeople);
License
MIT © Addy Osmani