UNPKG

@aureooms/js-odd-even-mergesort

Version:

Batcher's odd-even mergesort algorithm for JavaScript

17 lines (10 loc) 317 B
/** * Number of modules required to merge two sorted lists of size m and n. * See TAOC Vol 3 (Networks for Sorting). */ export function C ( m , n ) { if ( m * n <= 1 ) return m * n ; const _m = m / 2 | 0 ; const _n = n / 2 | 0 ; return C( m - _m , n - _n ) + C( _m , _n ) + ( ( m + n - 1 ) / 2 | 0 ) ; }