File tree Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Expand file tree Collapse file tree 4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,4 @@ class BHNode<T> {
44 constructor ( public key : T , public val : number ) { }
55}
66
7- export = BHNode ;
7+ export default BHNode ;
Original file line number Diff line number Diff line change @@ -343,4 +343,4 @@ class MinHeap<T> {
343343 } ;
344344}
345345
346- export = MinHeap ;
346+ export default MinHeap ;
Original file line number Diff line number Diff line change 1+ import heapSort from "./heapSort" ;
2+
3+ describe ( "Heap Sort Test" , ( ) => {
4+ test ( "Testing if HS sort a random array" , ( ) => {
5+ const nTimes = 100 ;
6+ const SIZE = 100 ;
7+ for ( let i = 0 ; i < nTimes ; i ++ ) {
8+ const arr = Array . from ( { length : SIZE } , ( ) =>
9+ Math . floor ( Math . random ( ) * 1000 )
10+ ) ;
11+ const sortedArr = heapSort ( arr ) ;
12+ const jsSortedArr = arr . slice ( ) . sort ( ( a , b ) => a - b ) ;
13+ expect ( sortedArr ) . toEqual ( jsSortedArr ) ;
14+ }
15+ } ) ;
16+ } ) ;
Original file line number Diff line number Diff line change 1- const MinHeap = require ( "../data-structures/minHeap" ) ;
1+ import MinHeap from "../data-structures/heaps/ minHeap" ;
22
33const heapSort = ( arr : number [ ] ) => {
44 const minHeap = new MinHeap ( ) ;
55 const result = [ ] ;
6- minHeap . buildHeap ( arr ) ;
6+ minHeap . buildHeap ( arr , [ ... arr . keys ( ) ] ) ;
77 while ( ! minHeap . isEmpty ( ) ) {
8- result . push ( minHeap . dequeue ( ) . val ) ;
8+ result . push ( minHeap . dequeue ( ) ! . val ) ;
99 }
1010 return result ;
1111} ;
1212
13- export = heapSort ;
13+ export default heapSort ;
You can’t perform that action at this time.
0 commit comments