aureooms-js-odd-even-mergesort

Batcher's odd-even mergesort algorithm for JavaScript


Keywords
Batcher, algorithm, even, javascript, js, merge, mergesort, odd, odd-even, oddeven, sort, sorting, algorithms, sorting-algorithms, agpl, mergesort-algorithm
License
AGPL-3.0
Install
npm install aureooms-js-odd-even-mergesort@2.0.0

Documentation

@aureooms/js-odd-even-mergesort

Batcher's odd-even mergesort algorithm for JavaScript. See docs. Parent is @aureooms/js-sort.

import { whole } from 'aureooms-js-odd-even-mergesort' ;
import { list } from 'aureooms-js-itertools' ;
import { increasing } from 'aureooms-js-compare' ;
import { swap } from 'aureooms-js-array' ;
let modules = list( whole( 4 ) ) ;
modules ; // [ [ 0 , 1 ] , [ 2 , 3 ] , [ 0 , 2 ] , [ 1 , 3 ] , [ 1 , 2 ] ]

let a = [ 3 , 1 , 2 , 4 ] ;
for ( let [ i , j ] of modules ) if ( increasing( a[i] , a[j] ) > 0 ) swap( a , i , j ) ;

// 3 ----1------1----------- 1
//       |      |
// 1 ----3------|-3----2---- 2
//              | |    |
// 2 ------2----2-|----3---- 3
//         |      |
// 4 ------4------4--------- 4

a ; // [ 1 , 2 , 3 , 4 ]

NPM license NPM version Build Status Coverage Status Dependencies Status devDependencies Status Code Climate NPM downloads per month GitHub issues Documentation