priority-queue-typed 1.47.5 → 1.47.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +36 -18
  2. package/dist/data-structures/binary-tree/avl-tree.js +46 -29
  3. package/dist/data-structures/binary-tree/binary-tree.d.ts +158 -129
  4. package/dist/data-structures/binary-tree/binary-tree.js +182 -184
  5. package/dist/data-structures/binary-tree/bst.d.ts +73 -63
  6. package/dist/data-structures/binary-tree/bst.js +168 -169
  7. package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -17
  8. package/dist/data-structures/binary-tree/rb-tree.js +77 -31
  9. package/dist/data-structures/binary-tree/tree-multimap.d.ts +29 -40
  10. package/dist/data-structures/binary-tree/tree-multimap.js +66 -136
  11. package/dist/data-structures/graph/abstract-graph.js +1 -1
  12. package/dist/data-structures/hash/hash-map.d.ts +2 -6
  13. package/dist/data-structures/hash/hash-map.js +5 -8
  14. package/dist/data-structures/heap/heap.d.ts +19 -21
  15. package/dist/data-structures/heap/heap.js +52 -34
  16. package/dist/data-structures/heap/max-heap.d.ts +2 -5
  17. package/dist/data-structures/heap/max-heap.js +2 -2
  18. package/dist/data-structures/heap/min-heap.d.ts +2 -5
  19. package/dist/data-structures/heap/min-heap.js +2 -2
  20. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  21. package/dist/data-structures/linked-list/doubly-linked-list.js +9 -1
  22. package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  23. package/dist/data-structures/linked-list/singly-linked-list.js +8 -1
  24. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -5
  25. package/dist/data-structures/priority-queue/max-priority-queue.js +2 -2
  26. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -5
  27. package/dist/data-structures/priority-queue/min-priority-queue.js +2 -2
  28. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -5
  29. package/dist/data-structures/priority-queue/priority-queue.js +2 -2
  30. package/dist/data-structures/queue/deque.d.ts +1 -0
  31. package/dist/data-structures/queue/deque.js +3 -0
  32. package/dist/data-structures/queue/queue.d.ts +1 -0
  33. package/dist/data-structures/queue/queue.js +3 -0
  34. package/dist/data-structures/stack/stack.d.ts +2 -1
  35. package/dist/data-structures/stack/stack.js +10 -2
  36. package/dist/data-structures/trie/trie.d.ts +3 -0
  37. package/dist/data-structures/trie/trie.js +19 -4
  38. package/dist/interfaces/binary-tree.d.ts +4 -2
  39. package/dist/types/common.d.ts +7 -0
  40. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  41. package/dist/types/data-structures/binary-tree/bst.d.ts +2 -2
  42. package/dist/types/data-structures/hash/hash-map.d.ts +1 -2
  43. package/dist/types/data-structures/heap/heap.d.ts +4 -1
  44. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +2 -1
  45. package/package.json +2 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +61 -31
  47. package/src/data-structures/binary-tree/binary-tree.ts +283 -254
  48. package/src/data-structures/binary-tree/bst.ts +193 -170
  49. package/src/data-structures/binary-tree/rb-tree.ts +87 -32
  50. package/src/data-structures/binary-tree/tree-multimap.ts +76 -136
  51. package/src/data-structures/graph/abstract-graph.ts +1 -1
  52. package/src/data-structures/hash/hash-map.ts +8 -8
  53. package/src/data-structures/heap/heap.ts +57 -39
  54. package/src/data-structures/heap/max-heap.ts +5 -5
  55. package/src/data-structures/heap/min-heap.ts +5 -5
  56. package/src/data-structures/linked-list/doubly-linked-list.ts +10 -1
  57. package/src/data-structures/linked-list/singly-linked-list.ts +9 -1
  58. package/src/data-structures/priority-queue/max-priority-queue.ts +4 -3
  59. package/src/data-structures/priority-queue/min-priority-queue.ts +12 -12
  60. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  61. package/src/data-structures/queue/deque.ts +4 -0
  62. package/src/data-structures/queue/queue.ts +4 -0
  63. package/src/data-structures/stack/stack.ts +12 -3
  64. package/src/data-structures/trie/trie.ts +23 -4
  65. package/src/interfaces/binary-tree.ts +14 -2
  66. package/src/types/common.ts +15 -1
  67. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  68. package/src/types/data-structures/binary-tree/bst.ts +2 -3
  69. package/src/types/data-structures/hash/hash-map.ts +1 -2
  70. package/src/types/data-structures/heap/heap.ts +3 -1
  71. package/src/types/data-structures/priority-queue/priority-queue.ts +3 -1
@@ -14,12 +14,7 @@ export declare class HashMap<K = any, V = any> {
14
14
  protected readonly _sentinel: HashMapLinkedNode<K, V | undefined>;
15
15
  protected _hashFn: (key: K) => string;
16
16
  protected _objHashFn: (key: K) => object;
17
- /**
18
- * The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
19
- * @param options - The `options` parameter is an object that contains the `elements` property. The
20
- * `elements` property is an iterable that contains key-value pairs represented as arrays `[K, V]`.
21
- */
22
- constructor(options?: HashMapOptions<K, V>);
17
+ constructor(elements?: Iterable<[K, V]>, options?: HashMapOptions<K>);
23
18
  protected _size: number;
24
19
  get size(): number;
25
20
  /**
@@ -172,6 +167,7 @@ export declare class HashMap<K = any, V = any> {
172
167
  * The above function is an iterator that yields key-value pairs from a linked list.
173
168
  */
174
169
  [Symbol.iterator](): Generator<[K, V], void, unknown>;
170
+ print(): void;
175
171
  /**
176
172
  * Time Complexity: O(1)
177
173
  * Space Complexity: O(1)
@@ -10,13 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.HashMap = void 0;
11
11
  const utils_1 = require("../../utils");
12
12
  class HashMap {
13
- /**
14
- * The constructor initializes a HashMapLinkedNode with an optional iterable of key-value pairs.
15
- * @param options - The `options` parameter is an object that contains the `elements` property. The
16
- * `elements` property is an iterable that contains key-value pairs represented as arrays `[K, V]`.
17
- */
18
- constructor(options = {
19
- elements: [],
13
+ constructor(elements, options = {
20
14
  hashFn: (key) => String(key),
21
15
  objHashFn: (key) => key
22
16
  }) {
@@ -25,7 +19,7 @@ class HashMap {
25
19
  this._size = 0;
26
20
  this._sentinel = {};
27
21
  this._sentinel.prev = this._sentinel.next = this._head = this._tail = this._sentinel;
28
- const { elements, hashFn, objHashFn } = options;
22
+ const { hashFn, objHashFn } = options;
29
23
  this._hashFn = hashFn;
30
24
  this._objHashFn = objHashFn;
31
25
  if (elements) {
@@ -347,6 +341,9 @@ class HashMap {
347
341
  node = node.next;
348
342
  }
349
343
  }
344
+ print() {
345
+ console.log([...this]);
346
+ }
350
347
  /**
351
348
  * Time Complexity: O(1)
352
349
  * Space Complexity: O(1)
@@ -5,15 +5,12 @@
5
5
  * @license MIT License
6
6
  */
7
7
  import type { Comparator, DFSOrderPattern } from '../../types';
8
+ import { HeapOptions } from "../../types";
8
9
  export declare class Heap<E = any> {
9
- constructor(options: {
10
- comparator: Comparator<E>;
11
- elements?: E[];
12
- });
10
+ options: HeapOptions<E>;
11
+ constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
13
12
  protected _elements: E[];
14
13
  get elements(): E[];
15
- protected _comparator: Comparator<E>;
16
- get comparator(): Comparator<E>;
17
14
  /**
18
15
  * Get the size (number of elements) of the heap.
19
16
  */
@@ -26,10 +23,10 @@ export declare class Heap<E = any> {
26
23
  /**
27
24
  * Static method that creates a binary heap from an array of elements and a comparison function.
28
25
  * @returns A new Heap instance.
26
+ * @param elements
29
27
  * @param options
30
28
  */
31
- static heapify<E>(options: {
32
- elements: E[];
29
+ static heapify<E>(elements: Iterable<E>, options: {
33
30
  comparator: Comparator<E>;
34
31
  }): Heap<E>;
35
32
  /**
@@ -204,6 +201,11 @@ export declare class Heap<E = any> {
204
201
  * Time Complexity: O(log n)
205
202
  * Space Complexity: O(1)
206
203
  */
204
+ print(): void;
205
+ /**
206
+ * Time Complexity: O(n)
207
+ * Space Complexity: O(1)
208
+ */
207
209
  /**
208
210
  * Time Complexity: O(log n)
209
211
  * Space Complexity: O(1)
@@ -212,10 +214,6 @@ export declare class Heap<E = any> {
212
214
  * @param index - The index of the newly added element.
213
215
  */
214
216
  protected _bubbleUp(index: number): void;
215
- /**
216
- * Time Complexity: O(n)
217
- * Space Complexity: O(1)
218
- */
219
217
  /**
220
218
  * Time Complexity: O(log n)
221
219
  * Space Complexity: O(1)
@@ -349,18 +347,18 @@ export declare class FibonacciHeap<E> {
349
347
  */
350
348
  merge(heapToMerge: FibonacciHeap<E>): void;
351
349
  /**
352
- * Default comparator function used by the heap.
353
- * @param {E} a
354
- * @param {E} b
350
+ * Create a new node.
351
+ * @param element
355
352
  * @protected
356
353
  */
357
- protected defaultComparator(a: E, b: E): number;
354
+ createNode(element: E): FibonacciHeapNode<E>;
358
355
  /**
359
- * Create a new node.
360
- * @param element
356
+ * Default comparator function used by the heap.
357
+ * @param {E} a
358
+ * @param {E} b
361
359
  * @protected
362
360
  */
363
- protected createNode(element: E): FibonacciHeapNode<E>;
361
+ protected _defaultComparator(a: E, b: E): number;
364
362
  /**
365
363
  * Time Complexity: O(1)
366
364
  * Space Complexity: O(1)
@@ -399,7 +397,7 @@ export declare class FibonacciHeap<E> {
399
397
  * @param x
400
398
  * @protected
401
399
  */
402
- protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
400
+ protected _link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
403
401
  /**
404
402
  * Time Complexity: O(n log n), where n is the number of elements in the heap.
405
403
  * Space Complexity: O(n)
@@ -411,5 +409,5 @@ export declare class FibonacciHeap<E> {
411
409
  * Remove and return the top element (smallest or largest element) from the heap.
412
410
  * @protected
413
411
  */
414
- protected consolidate(): void;
412
+ protected _consolidate(): void;
415
413
  }
@@ -8,20 +8,34 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.FibonacciHeap = exports.FibonacciHeapNode = exports.Heap = void 0;
10
10
  class Heap {
11
- constructor(options) {
11
+ constructor(elements, options) {
12
12
  this._elements = [];
13
- this._comparator = options.comparator;
14
- if (options.elements && options.elements.length > 0) {
15
- this._elements = options.elements;
16
- this.fix();
13
+ const defaultComparator = (a, b) => {
14
+ if (!(typeof a === 'number' && typeof b === 'number')) {
15
+ throw new Error('The a, b params of compare function must be number');
16
+ }
17
+ else {
18
+ return a - b;
19
+ }
20
+ };
21
+ if (options) {
22
+ this.options = options;
23
+ }
24
+ else {
25
+ this.options = {
26
+ comparator: defaultComparator
27
+ };
28
+ }
29
+ if (elements) {
30
+ for (const el of elements) {
31
+ this.push(el);
32
+ }
33
+ // this.fix();
17
34
  }
18
35
  }
19
36
  get elements() {
20
37
  return this._elements;
21
38
  }
22
- get comparator() {
23
- return this._comparator;
24
- }
25
39
  /**
26
40
  * Get the size (number of elements) of the heap.
27
41
  */
@@ -39,10 +53,11 @@ class Heap {
39
53
  /**
40
54
  * Static method that creates a binary heap from an array of elements and a comparison function.
41
55
  * @returns A new Heap instance.
56
+ * @param elements
42
57
  * @param options
43
58
  */
44
- static heapify(options) {
45
- return new Heap(options);
59
+ static heapify(elements, options) {
60
+ return new Heap(elements, options);
46
61
  }
47
62
  /**
48
63
  * Time Complexity: O(log n), where n is the number of elements in the heap.
@@ -256,7 +271,7 @@ class Heap {
256
271
  * @returns A new Heap instance containing the same elements.
257
272
  */
258
273
  clone() {
259
- const clonedHeap = new Heap({ comparator: this.comparator });
274
+ const clonedHeap = new Heap([], this.options);
260
275
  clonedHeap._elements = [...this.elements];
261
276
  return clonedHeap;
262
277
  }
@@ -308,7 +323,7 @@ class Heap {
308
323
  }
309
324
  }
310
325
  filter(predicate) {
311
- const filteredHeap = new Heap({ comparator: this.comparator });
326
+ const filteredHeap = new Heap([], this.options);
312
327
  let index = 0;
313
328
  for (const el of this) {
314
329
  if (predicate(el, index, this)) {
@@ -319,7 +334,7 @@ class Heap {
319
334
  return filteredHeap;
320
335
  }
321
336
  map(callback, comparator) {
322
- const mappedHeap = new Heap({ comparator: comparator });
337
+ const mappedHeap = new Heap([], { comparator: comparator });
323
338
  let index = 0;
324
339
  for (const el of this) {
325
340
  mappedHeap.add(callback(el, index, this));
@@ -340,6 +355,13 @@ class Heap {
340
355
  * Time Complexity: O(log n)
341
356
  * Space Complexity: O(1)
342
357
  */
358
+ print() {
359
+ console.log([...this]);
360
+ }
361
+ /**
362
+ * Time Complexity: O(n)
363
+ * Space Complexity: O(1)
364
+ */
343
365
  /**
344
366
  * Time Complexity: O(log n)
345
367
  * Space Complexity: O(1)
@@ -352,17 +374,13 @@ class Heap {
352
374
  while (index > 0) {
353
375
  const parent = (index - 1) >> 1;
354
376
  const parentItem = this.elements[parent];
355
- if (this._comparator(parentItem, element) <= 0)
377
+ if (this.options.comparator(parentItem, element) <= 0)
356
378
  break;
357
379
  this.elements[index] = parentItem;
358
380
  index = parent;
359
381
  }
360
382
  this.elements[index] = element;
361
383
  }
362
- /**
363
- * Time Complexity: O(n)
364
- * Space Complexity: O(1)
365
- */
366
384
  /**
367
385
  * Time Complexity: O(log n)
368
386
  * Space Complexity: O(1)
@@ -378,11 +396,11 @@ class Heap {
378
396
  const right = left + 1;
379
397
  let minItem = this.elements[left];
380
398
  if (right < this.elements.length &&
381
- this._comparator(minItem, this.elements[right]) > 0) {
399
+ this.options.comparator(minItem, this.elements[right]) > 0) {
382
400
  left = right;
383
401
  minItem = this.elements[right];
384
402
  }
385
- if (this._comparator(minItem, element) >= 0)
403
+ if (this.options.comparator(minItem, element) >= 0)
386
404
  break;
387
405
  this.elements[index] = minItem;
388
406
  index = left;
@@ -403,7 +421,7 @@ class FibonacciHeap {
403
421
  constructor(comparator) {
404
422
  this._size = 0;
405
423
  this.clear();
406
- this._comparator = comparator || this.defaultComparator;
424
+ this._comparator = comparator || this._defaultComparator;
407
425
  if (typeof this.comparator !== 'function') {
408
426
  throw new Error('FibonacciHeap constructor: given comparator should be a function.');
409
427
  }
@@ -574,7 +592,7 @@ class FibonacciHeap {
574
592
  }
575
593
  else {
576
594
  this._min = z.right;
577
- this.consolidate();
595
+ this._consolidate();
578
596
  }
579
597
  this._size--;
580
598
  return z.element;
@@ -614,27 +632,27 @@ class FibonacciHeap {
614
632
  // Clear the heap that was merged
615
633
  heapToMerge.clear();
616
634
  }
635
+ /**
636
+ * Create a new node.
637
+ * @param element
638
+ * @protected
639
+ */
640
+ createNode(element) {
641
+ return new FibonacciHeapNode(element);
642
+ }
617
643
  /**
618
644
  * Default comparator function used by the heap.
619
645
  * @param {E} a
620
646
  * @param {E} b
621
647
  * @protected
622
648
  */
623
- defaultComparator(a, b) {
649
+ _defaultComparator(a, b) {
624
650
  if (a < b)
625
651
  return -1;
626
652
  if (a > b)
627
653
  return 1;
628
654
  return 0;
629
655
  }
630
- /**
631
- * Create a new node.
632
- * @param element
633
- * @protected
634
- */
635
- createNode(element) {
636
- return new FibonacciHeapNode(element);
637
- }
638
656
  /**
639
657
  * Time Complexity: O(1)
640
658
  * Space Complexity: O(1)
@@ -690,7 +708,7 @@ class FibonacciHeap {
690
708
  * @param x
691
709
  * @protected
692
710
  */
693
- link(y, x) {
711
+ _link(y, x) {
694
712
  this.removeFromRoot(y);
695
713
  y.left = y;
696
714
  y.right = y;
@@ -709,7 +727,7 @@ class FibonacciHeap {
709
727
  * Remove and return the top element (smallest or largest element) from the heap.
710
728
  * @protected
711
729
  */
712
- consolidate() {
730
+ _consolidate() {
713
731
  const A = new Array(this.size);
714
732
  const elements = this.consumeLinkedList(this.root);
715
733
  let x, y, d, t;
@@ -723,7 +741,7 @@ class FibonacciHeap {
723
741
  x = y;
724
742
  y = t;
725
743
  }
726
- this.link(y, x);
744
+ this._link(y, x);
727
745
  A[d] = undefined;
728
746
  d++;
729
747
  }
@@ -6,10 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { Heap } from './heap';
9
- import type { Comparator } from '../../types';
9
+ import type { HeapOptions } from '../../types';
10
10
  export declare class MaxHeap<E = any> extends Heap<E> {
11
- constructor(options?: {
12
- comparator: Comparator<E>;
13
- nodes?: E[];
14
- });
11
+ constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
15
12
  }
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MaxHeap = void 0;
11
11
  const heap_1 = require("./heap");
12
12
  class MaxHeap extends heap_1.Heap {
13
- constructor(options = {
13
+ constructor(elements, options = {
14
14
  comparator: (a, b) => {
15
15
  if (!(typeof a === 'number' && typeof b === 'number')) {
16
16
  throw new Error('The a, b params of compare function must be number');
@@ -20,7 +20,7 @@ class MaxHeap extends heap_1.Heap {
20
20
  }
21
21
  }
22
22
  }) {
23
- super(options);
23
+ super(elements, options);
24
24
  }
25
25
  }
26
26
  exports.MaxHeap = MaxHeap;
@@ -6,10 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { Heap } from './heap';
9
- import type { Comparator } from '../../types';
9
+ import type { HeapOptions } from '../../types';
10
10
  export declare class MinHeap<E = any> extends Heap<E> {
11
- constructor(options?: {
12
- comparator: Comparator<E>;
13
- nodes?: E[];
14
- });
11
+ constructor(elements?: Iterable<E>, options?: HeapOptions<E>);
15
12
  }
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MinHeap = void 0;
11
11
  const heap_1 = require("./heap");
12
12
  class MinHeap extends heap_1.Heap {
13
- constructor(options = {
13
+ constructor(elements, options = {
14
14
  comparator: (a, b) => {
15
15
  if (!(typeof a === 'number' && typeof b === 'number')) {
16
16
  throw new Error('The a, b params of compare function must be number');
@@ -20,7 +20,7 @@ class MinHeap extends heap_1.Heap {
20
20
  }
21
21
  }
22
22
  }) {
23
- super(options);
23
+ super(elements, options);
24
24
  }
25
25
  }
26
26
  exports.MinHeap = MinHeap;
@@ -20,7 +20,7 @@ export declare class DoublyLinkedList<E = any> {
20
20
  /**
21
21
  * The constructor initializes the linked list with an empty head, tail, and length.
22
22
  */
23
- constructor();
23
+ constructor(elements?: Iterable<E>);
24
24
  protected _head: DoublyLinkedListNode<E> | null;
25
25
  get head(): DoublyLinkedListNode<E> | null;
26
26
  protected _tail: DoublyLinkedListNode<E> | null;
@@ -453,4 +453,5 @@ export declare class DoublyLinkedList<E = any> {
453
453
  * elements in the linked list.
454
454
  */
455
455
  reduce<T>(callback: (accumulator: T, value: E, index: number, list: DoublyLinkedList<E>) => T, initialValue: T): T;
456
+ print(): void;
456
457
  }
@@ -25,10 +25,15 @@ class DoublyLinkedList {
25
25
  /**
26
26
  * The constructor initializes the linked list with an empty head, tail, and length.
27
27
  */
28
- constructor() {
28
+ constructor(elements) {
29
29
  this._head = null;
30
30
  this._tail = null;
31
31
  this._length = 0;
32
+ if (elements) {
33
+ for (const el of elements) {
34
+ this.push(el);
35
+ }
36
+ }
32
37
  }
33
38
  get head() {
34
39
  return this._head;
@@ -766,5 +771,8 @@ class DoublyLinkedList {
766
771
  }
767
772
  return accumulator;
768
773
  }
774
+ print() {
775
+ console.log([...this]);
776
+ }
769
777
  }
770
778
  exports.DoublyLinkedList = DoublyLinkedList;
@@ -19,7 +19,7 @@ export declare class SinglyLinkedList<E = any> {
19
19
  /**
20
20
  * The constructor initializes the linked list with an empty head, tail, and length.
21
21
  */
22
- constructor();
22
+ constructor(elements?: Iterable<E>);
23
23
  protected _head: SinglyLinkedListNode<E> | null;
24
24
  get head(): SinglyLinkedListNode<E> | null;
25
25
  protected _tail: SinglyLinkedListNode<E> | null;
@@ -411,4 +411,5 @@ export declare class SinglyLinkedList<E = any> {
411
411
  * elements in the linked list.
412
412
  */
413
413
  reduce<T>(callback: (accumulator: T, value: E, index: number, list: SinglyLinkedList<E>) => T, initialValue: T): T;
414
+ print(): void;
414
415
  }
@@ -24,10 +24,14 @@ class SinglyLinkedList {
24
24
  /**
25
25
  * The constructor initializes the linked list with an empty head, tail, and length.
26
26
  */
27
- constructor() {
27
+ constructor(elements) {
28
28
  this._head = null;
29
29
  this._tail = null;
30
30
  this._length = 0;
31
+ if (elements) {
32
+ for (const el of elements)
33
+ this.push(el);
34
+ }
31
35
  }
32
36
  get head() {
33
37
  return this._head;
@@ -709,5 +713,8 @@ class SinglyLinkedList {
709
713
  }
710
714
  return accumulator;
711
715
  }
716
+ print() {
717
+ console.log([...this]);
718
+ }
712
719
  }
713
720
  exports.SinglyLinkedList = SinglyLinkedList;
@@ -6,10 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { PriorityQueue } from './priority-queue';
9
- import type { Comparator } from '../../types';
9
+ import type { PriorityQueueOptions } from '../../types';
10
10
  export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
11
- constructor(options?: {
12
- comparator: Comparator<E>;
13
- nodes?: E[];
14
- });
11
+ constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
15
12
  }
@@ -10,7 +10,7 @@ exports.MaxPriorityQueue = void 0;
10
10
  */
11
11
  const priority_queue_1 = require("./priority-queue");
12
12
  class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
13
- constructor(options = {
13
+ constructor(elements, options = {
14
14
  comparator: (a, b) => {
15
15
  if (!(typeof a === 'number' && typeof b === 'number')) {
16
16
  throw new Error('The a, b params of compare function must be number');
@@ -20,7 +20,7 @@ class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
20
20
  }
21
21
  }
22
22
  }) {
23
- super(options);
23
+ super(elements, options);
24
24
  }
25
25
  }
26
26
  exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -6,10 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { PriorityQueue } from './priority-queue';
9
- import type { Comparator } from '../../types';
9
+ import type { PriorityQueueOptions } from '../../types';
10
10
  export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
11
- constructor(options?: {
12
- comparator: Comparator<E>;
13
- nodes?: E[];
14
- });
11
+ constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
15
12
  }
@@ -10,7 +10,7 @@ exports.MinPriorityQueue = void 0;
10
10
  */
11
11
  const priority_queue_1 = require("./priority-queue");
12
12
  class MinPriorityQueue extends priority_queue_1.PriorityQueue {
13
- constructor(options = {
13
+ constructor(elements, options = {
14
14
  comparator: (a, b) => {
15
15
  if (!(typeof a === 'number' && typeof b === 'number')) {
16
16
  throw new Error('The a, b params of compare function must be number');
@@ -20,7 +20,7 @@ class MinPriorityQueue extends priority_queue_1.PriorityQueue {
20
20
  }
21
21
  }
22
22
  }) {
23
- super(options);
23
+ super(elements, options);
24
24
  }
25
25
  }
26
26
  exports.MinPriorityQueue = MinPriorityQueue;
@@ -6,10 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { Heap } from '../heap';
9
- import { Comparator } from '../../types';
9
+ import { PriorityQueueOptions } from '../../types';
10
10
  export declare class PriorityQueue<E = any> extends Heap<E> {
11
- constructor(options: {
12
- comparator: Comparator<E>;
13
- nodes?: E[];
14
- });
11
+ constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
15
12
  }
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.PriorityQueue = void 0;
11
11
  const heap_1 = require("../heap");
12
12
  class PriorityQueue extends heap_1.Heap {
13
- constructor(options) {
14
- super(options);
13
+ constructor(elements, options) {
14
+ super(elements, options);
15
15
  }
16
16
  }
17
17
  exports.PriorityQueue = PriorityQueue;
@@ -428,6 +428,7 @@ export declare class Deque<E> {
428
428
  * applying the callback function to each element.
429
429
  */
430
430
  reduce<T>(callback: (accumulator: T, element: E, index: number, deque: this) => T, initialValue: T): T;
431
+ print(): void;
431
432
  /**
432
433
  * Time Complexity: O(n)
433
434
  * Space Complexity: O(n)
@@ -761,6 +761,9 @@ class Deque {
761
761
  }
762
762
  return accumulator;
763
763
  }
764
+ print() {
765
+ console.log([...this]);
766
+ }
764
767
  /**
765
768
  * Time Complexity: O(n)
766
769
  * Space Complexity: O(n)
@@ -205,6 +205,7 @@ export declare class Queue<E = any> {
205
205
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
206
206
  */
207
207
  clone(): Queue<E>;
208
+ print(): void;
208
209
  [Symbol.iterator](): Generator<E, void, unknown>;
209
210
  /**
210
211
  * Time Complexity: O(n)
@@ -265,6 +265,9 @@ class Queue {
265
265
  clone() {
266
266
  return new Queue(this.nodes.slice(this.offset));
267
267
  }
268
+ print() {
269
+ console.log([...this]);
270
+ }
268
271
  *[Symbol.iterator]() {
269
272
  for (const item of this.nodes) {
270
273
  yield item;
@@ -10,7 +10,7 @@ export declare class Stack<E = any> {
10
10
  * of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
11
11
  * is provided and is an array, it is assigned to the `_elements
12
12
  */
13
- constructor(elements?: E[]);
13
+ constructor(elements?: Iterable<E>);
14
14
  protected _elements: E[];
15
15
  get elements(): E[];
16
16
  /**
@@ -116,4 +116,5 @@ export declare class Stack<E = any> {
116
116
  filter(predicate: (element: E, index: number, stack: this) => boolean): Stack<E>;
117
117
  map<T>(callback: (element: E, index: number, stack: this) => T): Stack<T>;
118
118
  reduce<T>(callback: (accumulator: T, element: E, index: number, stack: this) => T, initialValue: T): T;
119
+ print(): void;
119
120
  }