Home Manual Reference Source

Overview

Installation

Can be managed using jspm or npm.

jspm

jspm install npm:@comparison-sorting/heap-sort

npm

npm install @comparison-sorting/heap-sort --save

Usage

Import where needed:

const heapSort = await import('@comparison-sorting/heap-sort');
// or
import * as heapSort from '@comparison-sorting/heap-sort';

Examples

import * as compare from '@total-order/primitive';
import * as heapSort from '@comparison-sorting/heap-sort';

/** binary heap-sort */
let sort = heapSort.dary( 2 ) ;

let a = [ 1 , 6 , 5 , 3 , 2 , 4 ] ;

sort( compare.increasing , a , 0 , a.length ) ;

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

sort( compare.decreasing , a , 0 , a.length ) ;

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

// but also

/** ternary heap-sort */
let sort = heapSort.dary( 3 ) ;
/** quaternary heap-sort */
let sort = heapSort.dary( 4 ) ;
/** etc... */
let sort = heapSort.dary( 5 ) ;