bubble-srt
v1.0.0
Published
Bubble Sort Algorithm Implementation
Downloads
6
Maintainers
Readme
Overview
Bubble sort, sometimes referred to as sinking 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.
The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list. Although the algorithm is simple, it is too slow and impractical for most problems even when compared to insertion sort. Bubble sort can be practical if the input is in mostly sorted order with some out-of-order elements nearly in position
Install
npm install bubble-srt
Usage
const bubbleSort = require('bubble-srt');
let numsArr = [46, 24, 33, 10, 2, 81, 50];
console.log(bubbleSort(numsArr));
// => [ 2, 10, 24, 33, 46, 50, 81 ]
let lettersArr = ['d', 'h', 'z', 'a', 'r', 'b', 'i'];
console.log(bubbleSort(lettersArr));
// => [ 'a', 'b', 'd', 'h', 'i', 'r', 'z' ]
let wordsArr = ['happy', 'auto', 'energy', 'zoo', 'trigonometry', 'dog', 'foo'];
console.log(bubbleSort(wordsArr));
// => [ 'auto', 'dog', 'energy', 'foo', 'happy', 'trigonometry', 'zoo' ]
Related
- bubble-srt-cli: CLI for this module
Team
|| | :-: | | Carlos Abraham |
License
MIT License © Carlos Abraham