Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/abranhe/bubble-srt

Bubble Sort Algorithm Implementation
https://github.com/abranhe/bubble-srt

algorithm bubble-sort sorting-algorithms

Last synced: 4 days ago
JSON representation

Bubble Sort Algorithm Implementation

Awesome Lists containing this project

README

        









bubble-srt
: Bubble Sort Algorithm Implementation
















# 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

```js
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](https://github.com/abranhe/bubble-srt-cli): CLI for this module
# Team

|[![Carlos Abraham Logo](https://avatars3.githubusercontent.com/u/21347264?s=50&v=4)](https://19cah.com)|
| :-: |
| [Carlos Abraham](https://github.com/abranhe) |

# License

[MIT](https://github.com/abranhe/bubble-srt/blob/master/LICENSE) License © [Carlos Abraham](https://github.com/abranhe/)