make-github-pseudonymous-again/js-sorting

more obvious tapemerge implementation

make-github-pseudonymous-again opened this issue · 2 comments

use

while ( true ) {

    if ( ai >= aj ) {
        while ( bi < bj ) { ... }
        return ;
    }

    if ( bi >= bj ) {
        do { ... } while ( ai < aj ) ;
        return ;
    }

    if ( compare( a[ai] , b[bi] ) <= 0 ) {
        ...
    }

    else {
        ...
    }

    ++ci ;

}

make sure the new version keeps merge sort stable, i.e.

if ( compare( a[ai] , b[bi] ) === 0 ) {
    c[ci] = a[ai] ;
    ...
}