diff --git a/README.md b/README.md
index 80bfbed..455c87f 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,8 @@ Data Structures of Javascript & TypeScript.
A library that provides a variety of JavaScript and TypeScript data structures, as well as implementations of some
classic algorithms.
+Do you envy languages like C++ with *std*, Python with *collections*, and Java with *java.util*? Well, no need to envy anymore! JavaScript and TypeScript now have *data-structure-typed*
+
![License](https://img.shields.io/badge/License-MIT-blue.svg)
![Language](https://img.shields.io/github/languages/top/zrwusa/data-structure-typed)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/zrwusa/data-structure-typed)
@@ -682,245 +684,183 @@ optimal approach to data structure design.
-
- Data Structure |
- C++ STL |
- java.util |
- Python collections |
- Data Structure Typed |
-
+
+ Data Structure |
+ C++ std |
+ Data Structure Typed |
+ java.util |
+ Python collections |
+
-
- Dynamic Array (ArrayList) |
- std::vector<T> |
- ArrayList<E> |
- list |
- Array |
-
-
- Linked List |
- std::list<T> |
- LinkedList<E> |
- deque |
- DoublyLinkedList |
-
-
- Set |
- std::set<T> |
- HashSet<E> |
- set |
- Set |
-
-
- Map |
- std::map<K, V> |
- HashMap<K, V> |
- dict |
- Map |
-
-
- Stack |
- std::stack<T> |
- Stack<E> |
- N/A |
- Stack |
-
-
- Queue |
- std::queue<T> |
- Queue<E> |
- N/A |
- Queue |
-
-
- Priority Queue |
- std::priority_queue<T> |
- PriorityQueue<E> |
- N/A |
- PriorityQueue |
-
-
- Hash Table |
- N/A |
- Hashtable |
- defaultdict |
- HashTable |
-
-
- Deque |
- std::deque<T> |
- N/A |
- N/A |
- Deque |
-
-
- Multiset |
- std::multiset<T> |
- N/A |
- N/A |
- N/A |
-
-
- Multimap |
- std::multimap<K, V> |
- N/A |
- N/A |
- N/A |
-
-
- Unordered Set |
- std::unordered_set<T> |
- HashSet<E> |
- N/A |
- N/A |
-
-
- Unordered Multiset |
- std::unordered_multiset |
- N/A |
- Counter |
- N/A |
-
-
- Unordered Map |
- std::unordered_map<K, V> |
- HashMap<K, V> |
- defaultdict |
- N/A |
-
-
- Unordered Multimap |
- std::unordered_multimap<K, V> |
- N/A |
- N/A |
- N/A |
-
-
- Bitset |
- std::bitset<N> |
- N/A |
- N/A |
- N/A |
-
-
- Ordered Dictionary |
- N/A |
- N/A |
- OrderedDict |
- Map |
-
-
- Double-Ended Queue (Deque) |
- std::deque<T> |
- N/A |
- N/A |
- Deque |
-
-
- Linked Hash Set |
- N/A |
- LinkedHashSet<E> |
- N/A |
- N/A |
-
-
- Linked Hash Map |
- N/A |
- LinkedHashMap<K, V> |
- N/A |
- N/A |
-
-
- Sorted Set |
- N/A |
- TreeSet<E> |
- N/A |
- AVLTree, RBTree |
-
-
- Sorted Map |
- N/A |
- TreeMap<K, V> |
- N/A |
- AVLTree, RBTree |
-
-
- Tree Set |
- std::set |
- TreeSet<E> |
- N/A |
- AVLTree, RBTree |
-
-
- Tree Map |
- std::map<K, V> |
- TreeMap<K, V> |
- N/A |
- AVLTree, RBTree |
-
-
- Persistent Collections |
- N/A |
- N/A |
- N/A |
- N/A |
-
-
- unordered multiset |
- unordered multiset<T> |
- N/A |
- N/A |
- N/A |
-
-
- Unordered Multimap |
- std::unordered_multimap<K, V> |
- N/A |
- N/A |
- N/A |
-
-
- N/A |
- LinkedBlockingQueue<E> |
- N/A |
- N/A |
- N/A |
-
-
- N/A |
- ConcurrentHashMap<K, V> |
- N/A |
- N/A |
- N/A |
-
-
- N/A |
- N/A |
- namedtuple |
- N/A |
- N/A |
-
-
- N/A |
- N/A |
- ChainMap |
- N/A |
- N/A |
-
-
- N/A |
- N/A |
- defaultdict |
- N/A |
- N/A |
-
-
- N/A |
- N/A |
- Counter |
- N/A |
- N/A |
-
+
+ Dynamic Array |
+ std::vector<T> |
+ Array<E> |
+ ArrayList<E> |
+ list |
+
+
+ Linked List |
+ std::list<T> |
+ DoublyLinkedList<E> |
+ LinkedList<E> |
+ deque |
+
+
+ Set |
+ std::set<T> |
+ Set |
+ HashSet<E> |
+ set |
+
+
+ Map |
+ std::map<K, V> |
+ Map |
+ HashMap<K, V> |
+ dict |
+
+
+ Unordered Map |
+ std::unordered_map<K, V> |
+ N/A |
+ HashMap<K, V> |
+ defaultdict |
+
+
+ Unordered Set |
+ std::unordered_set<T> |
+ N/A |
+ HashSet<E> |
+ N/A |
+
+
+ Queue |
+ std::queue<T> |
+ Queue |
+ Queue<E> |
+ N/A |
+
+
+ Priority Queue |
+ std::priority_queue<T> |
+ PriorityQueue |
+ PriorityQueue<E> |
+ N/A |
+
+
+ Stack |
+ std::stack<T> |
+ Stack |
+ Stack<E> |
+ N/A |
+
+
+ Bitset |
+ std::bitset<N> |
+ N/A |
+ N/A |
+ N/A |
+
+
+ Deque |
+ std::deque<T> |
+ Deque |
+ N/A |
+ N/A |
+
+
+ Multiset |
+ std::multiset<T> |
+ N/A |
+ N/A |
+ N/A |
+
+
+ Multimap |
+ std::multimap<K, V> |
+ N/A |
+ N/A |
+ N/A |
+
+
+ Unordered Multiset |
+ std::unordered_multiset |
+ N/A |
+ Counter |
+ N/A |
+
+
+ Ordered Dictionary |
+ N/A |
+ Map |
+ N/A |
+ OrderedDict |
+
+
+ Double-Ended Queue (Deque) |
+ std::deque<T> |
+ Deque |
+ N/A |
+ N/A |
+
+
+ Linked Hash Set |
+ N/A |
+ N/A |
+ LinkedHashSet<E> |
+ N/A |
+
+
+ Linked Hash Map |
+ N/A |
+ N/A |
+ LinkedHashMap<K, V> |
+ N/A |
+
+
+ Sorted Set |
+ N/A |
+ AVLTree, RBTree |
+ TreeSet<E> |
+ N/A |
+
+
+ Sorted Map |
+ N/A |
+ AVLTree, RBTree |
+ TreeMap<K, V> |
+ N/A |
+
+
+ Tree Set |
+ std::set |
+ AVLTree, RBTree |
+ TreeSet<E> |
+ N/A |
+
+
+ Persistent Collections |
+ N/A |
+ N/A |
+ N/A |
+ N/A |
+
+
+ unordered multiset |
+ unordered multiset<T> |
+ N/A |
+ N/A |
+ N/A |
+
+
+ Unordered Multimap |
+ std::unordered_multimap<K, V> |
+ N/A |
+ N/A |
+ N/A |
+
+
diff --git a/src/data-structures/binary-tree/abstract-binary-tree.ts b/src/data-structures/binary-tree/abstract-binary-tree.ts
index e86241e..b1addc9 100644
--- a/src/data-structures/binary-tree/abstract-binary-tree.ts
+++ b/src/data-structures/binary-tree/abstract-binary-tree.ts
@@ -21,18 +21,18 @@ import {AbstractBinaryTreeOptions, FamilyPosition, LoopType} from '../../types';
import {IAbstractBinaryTree, IAbstractBinaryTreeNode} from '../../interfaces';
export abstract class AbstractBinaryTreeNode<
- T = any,
- NEIGHBOR extends AbstractBinaryTreeNode = AbstractBinaryTreeNodeNested
-> implements IAbstractBinaryTreeNode
+ V = any,
+ NEIGHBOR extends AbstractBinaryTreeNode = AbstractBinaryTreeNodeNested
+> implements IAbstractBinaryTreeNode
{
/**
* The constructor function initializes a BinaryTreeNode object with an id and an optional value.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* of the binary tree node. It is used to distinguish one node from another in the binary tree.
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value that will be
+ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It represents the value that will be
* stored in the binary tree node. If no value is provided, it will be set to undefined.
*/
- protected constructor(id: BinaryTreeNodeId, val?: T) {
+ protected constructor(id: BinaryTreeNodeId, val?: V) {
this._id = id;
this._val = val;
}
@@ -47,13 +47,13 @@ export abstract class AbstractBinaryTreeNode<
this._id = v;
}
- private _val: T | undefined;
+ private _val: V | undefined;
- get val(): T | undefined {
+ get val(): V | undefined {
return this._val;
}
- set val(value: T | undefined) {
+ set val(value: V | undefined) {
this._val = value;
}
diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts
index 4b33e1a..5f5814b 100644
--- a/src/data-structures/binary-tree/avl-tree.ts
+++ b/src/data-structures/binary-tree/avl-tree.ts
@@ -9,11 +9,11 @@ import {BST, BSTNode} from './bst';
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId} from '../../types';
import {IAVLTree, IAVLTreeNode} from '../../interfaces';
-export class AVLTreeNode = AVLTreeNodeNested>
- extends BSTNode
- implements IAVLTreeNode
+export class AVLTreeNode = AVLTreeNodeNested>
+ extends BSTNode
+ implements IAVLTreeNode
{
- constructor(id: BinaryTreeNodeId, val?: T) {
+ constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
}
}
diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts
index e56a12e..0f6c5d7 100644
--- a/src/data-structures/binary-tree/binary-tree.ts
+++ b/src/data-structures/binary-tree/binary-tree.ts
@@ -10,11 +10,11 @@ import type {BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions} from '..
import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree';
import {IBinaryTree, IBinaryTreeNode} from '../../interfaces';
-export class BinaryTreeNode = BinaryTreeNodeNested>
- extends AbstractBinaryTreeNode
- implements IBinaryTreeNode
+export class BinaryTreeNode = BinaryTreeNodeNested>
+ extends AbstractBinaryTreeNode
+ implements IBinaryTreeNode
{
- constructor(id: BinaryTreeNodeId, val?: T) {
+ constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
}
}
diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts
index c1ea1f4..6be2460 100644
--- a/src/data-structures/binary-tree/bst.ts
+++ b/src/data-structures/binary-tree/bst.ts
@@ -10,11 +10,11 @@ import {CP, LoopType} from '../../types';
import {BinaryTree, BinaryTreeNode} from './binary-tree';
import {IBST, IBSTNode} from '../../interfaces';
-export class BSTNode = BSTNodeNested>
- extends BinaryTreeNode
- implements IBSTNode
+export class BSTNode = BSTNodeNested>
+ extends BinaryTreeNode
+ implements IBSTNode
{
- constructor(id: BinaryTreeNodeId, val?: T) {
+ constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
}
}
diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts
index b61d28d..f230e7c 100644
--- a/src/data-structures/binary-tree/rb-tree.ts
+++ b/src/data-structures/binary-tree/rb-tree.ts
@@ -2,13 +2,13 @@ import {BinaryTreeNodeId, RBColor, RBTreeNodeNested, RBTreeOptions} from '../../
import {IRBTree, IRBTreeNode} from '../../interfaces';
import {BST, BSTNode} from './bst';
-export class RBTreeNode = RBTreeNodeNested>
- extends BSTNode
- implements IRBTreeNode
+export class RBTreeNode = RBTreeNodeNested>
+ extends BSTNode
+ implements IRBTreeNode
{
private _color: RBColor;
- constructor(id: BinaryTreeNodeId, val?: T) {
+ constructor(id: BinaryTreeNodeId, val?: V) {
super(id, val);
this._color = RBColor.RED;
}
diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts
index beec9d8..d5d8039 100644
--- a/src/data-structures/binary-tree/tree-multiset.ts
+++ b/src/data-structures/binary-tree/tree-multiset.ts
@@ -10,21 +10,21 @@ import {BinaryTreeDeletedResult, CP, DFSOrderPattern, FamilyPosition, LoopType}
import {ITreeMultiset, ITreeMultisetNode} from '../../interfaces';
import {AVLTree, AVLTreeNode} from './avl-tree';
-export class TreeMultisetNode = TreeMultisetNodeNested>
- extends AVLTreeNode
- implements ITreeMultisetNode
+export class TreeMultisetNode = TreeMultisetNodeNested>
+ extends AVLTreeNode
+ implements ITreeMultisetNode
{
/**
* The constructor function initializes a BinaryTreeNode object with an id, value, and count.
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
* of the binary tree node.
- * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value of the binary
+ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value of the binary
* tree node. If no value is provided, it will be `undefined`.
* @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
* occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
* parameter when creating a new instance of the `BinaryTreeNode` class,
*/
- constructor(id: BinaryTreeNodeId, val?: T, count = 1) {
+ constructor(id: BinaryTreeNodeId, val?: V, count = 1) {
super(id, val);
this._count = count;
}
diff --git a/src/data-structures/diagrams/README.md b/src/data-structures/diagrams/README.md
deleted file mode 100644
index ae3e799..0000000
--- a/src/data-structures/diagrams/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-// 操作 常见名称 Ada Java JavaScript C++ Python Perl PHP Ruby // 尾部插入 inject, snoc Append offerLast push push_back append push
-array_push push // 头部插入 push, cons Prepend offerFirst unshift push_front appendleft unshift array_unshift unshift //
-尾部删除 eject Delete_Last pollLast pop pop_back pop pop array_pop pop // 头部删除 pop Delete_First pollFirst shift pop_front
-popleft shift array_shift shift // 查看尾部 Last_Element peekLast [length - 1] back [-1] $array[-1] end
-last // 查看头部 First_Element peekFirst [0] front [0] $array[0] reset first
diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts
index c020eba..c17054d 100644
--- a/src/data-structures/graph/abstract-graph.ts
+++ b/src/data-structures/graph/abstract-graph.ts
@@ -10,15 +10,15 @@ import {PriorityQueue} from '../priority-queue';
import type {DijkstraResult, VertexId} from '../../types';
import {IAbstractGraph} from '../../interfaces';
-export abstract class AbstractVertex {
+export abstract class AbstractVertex {
/**
* The function is a protected constructor that takes an id and an optional value as parameters.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex object.
- * @param {T} [val] - The parameter "val" is an optional parameter of type T. It is used to assign a value to the
+ * @param {V} [val] - The parameter "val" is an optional parameter of type V. It is used to assign a value to the
* vertex. If no value is provided, it will be set to undefined.
*/
- protected constructor(id: VertexId, val?: T) {
+ protected constructor(id: VertexId, val?: V) {
this._id = id;
this._val = val;
}
@@ -33,40 +33,40 @@ export abstract class AbstractVertex {
this._id = v;
}
- private _val: T | undefined;
+ private _val: V | undefined;
- get val(): T | undefined {
+ get val(): V | undefined {
return this._val;
}
- set val(value: T | undefined) {
+ set val(value: V | undefined) {
this._val = value;
}
}
-export abstract class AbstractEdge {
+export abstract class AbstractEdge {
/**
* The above function is a protected constructor that initializes the weight, value, and hash code properties of an
* object.
* @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
* a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
* will be assigned.
- * @param {T} [val] - The `val` parameter is of type `T`, which means it can be any type. It is an optional parameter,
+ * @param {V} [val] - The `val` parameter is of type `V`, which means it can be any type. It is an optional parameter,
* meaning it can be omitted when creating an instance of the class.
*/
- protected constructor(weight?: number, val?: T) {
+ protected constructor(weight?: number, val?: V) {
this._weight = weight !== undefined ? weight : 1;
this._val = val;
this._hashCode = uuidV4();
}
- private _val: T | undefined;
+ private _val: V | undefined;
- get val(): T | undefined {
+ get val(): V | undefined {
return this._val;
}
- set val(value: T | undefined) {
+ set val(value: V | undefined) {
this._val = value;
}
diff --git a/src/data-structures/graph/directed-graph.ts b/src/data-structures/graph/directed-graph.ts
index f9da13e..0a2bcbd 100644
--- a/src/data-structures/graph/directed-graph.ts
+++ b/src/data-structures/graph/directed-graph.ts
@@ -10,20 +10,20 @@ import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
import type {TopologicalStatus, VertexId} from '../../types';
import {IDirectedGraph} from '../../interfaces';
-export class DirectedVertex extends AbstractVertex {
+export class DirectedVertex extends AbstractVertex {
/**
* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or data structure.
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
+ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
* vertex. If no value is provided, the vertex will be initialized with a default value.
*/
- constructor(id: VertexId, val?: T) {
+ constructor(id: VertexId, val?: V) {
super(id, val);
}
}
-export class DirectedEdge extends AbstractEdge {
+export class DirectedEdge extends AbstractEdge {
/**
* The constructor function initializes the source and destination vertices of an edge, along with an optional weight
* and value.
@@ -32,10 +32,10 @@ export class DirectedEdge extends AbstractEdge {
* @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
* `VertexId`, which is likely a unique identifier for a vertex in a graph.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
- * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
+ * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with
* the edge.
*/
- constructor(src: VertexId, dest: VertexId, weight?: number, val?: T) {
+ constructor(src: VertexId, dest: VertexId, weight?: number, val?: V) {
super(weight, val);
this._src = src;
this._dest = dest;
diff --git a/src/data-structures/graph/map-graph.ts b/src/data-structures/graph/map-graph.ts
index 9375e65..86412eb 100644
--- a/src/data-structures/graph/map-graph.ts
+++ b/src/data-structures/graph/map-graph.ts
@@ -1,7 +1,7 @@
import {MapGraphCoordinate, VertexId} from '../../types';
import {DirectedEdge, DirectedGraph, DirectedVertex} from './directed-graph';
-export class MapVertex extends DirectedVertex {
+export class MapVertex extends DirectedVertex {
/**
* The constructor function initializes an object with an id, latitude, longitude, and an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
@@ -11,10 +11,10 @@ export class MapVertex extends DirectedVertex {
* @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
* coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
* values ranging from -180 to 180.
- * @param {T} [val] - The "val" parameter is an optional value of type T. It is not required to be provided when
+ * @param {V} [val] - The "val" parameter is an optional value of type V. It is not required to be provided when
* creating an instance of the class.
*/
- constructor(id: VertexId, lat: number, long: number, val?: T) {
+ constructor(id: VertexId, lat: number, long: number, val?: V) {
super(id, val);
this._lat = lat;
this._long = long;
@@ -41,7 +41,7 @@ export class MapVertex extends DirectedVertex {
}
}
-export class MapEdge extends DirectedEdge {
+export class MapEdge extends DirectedEdge {
/**
* The constructor function initializes a new instance of a class with the given source, destination, weight, and
* value.
@@ -49,10 +49,10 @@ export class MapEdge extends DirectedEdge {
* a graph.
* @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store additional
+ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional
* information or data associated with the edge.
*/
- constructor(src: VertexId, dest: VertexId, weight?: number, val?: T) {
+ constructor(src: VertexId, dest: VertexId, weight?: number, val?: V) {
super(src, dest, weight, val);
}
}
diff --git a/src/data-structures/graph/undirected-graph.ts b/src/data-structures/graph/undirected-graph.ts
index 8550b64..da46161 100644
--- a/src/data-structures/graph/undirected-graph.ts
+++ b/src/data-structures/graph/undirected-graph.ts
@@ -10,20 +10,20 @@ import {AbstractEdge, AbstractGraph, AbstractVertex} from './abstract-graph';
import type {VertexId} from '../../types';
import {IUNDirectedGraph} from '../../interfaces';
-export class UndirectedVertex extends AbstractVertex {
+export class UndirectedVertex extends AbstractVertex {
/**
* The constructor function initializes a vertex with an optional value.
* @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
* used to uniquely identify the vertex within a graph or network.
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
+ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
* vertex. If no value is provided, the vertex will be initialized with a default value.
*/
- constructor(id: VertexId, val?: T) {
+ constructor(id: VertexId, val?: V) {
super(id, val);
}
}
-export class UndirectedEdge extends AbstractEdge {
+export class UndirectedEdge extends AbstractEdge {
/**
* The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
* value.
@@ -31,10 +31,10 @@ export class UndirectedEdge extends AbstractEdge {
* @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
* graph edge.
* @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
+ * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store a value associated
* with the edge.
*/
- constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T) {
+ constructor(v1: VertexId, v2: VertexId, weight?: number, val?: V) {
super(weight, val);
this._vertices = [v1, v2];
}
diff --git a/src/data-structures/heap/heap.ts b/src/data-structures/heap/heap.ts
index c59a57d..ecc452c 100644
--- a/src/data-structures/heap/heap.ts
+++ b/src/data-structures/heap/heap.ts
@@ -8,15 +8,15 @@
import {PriorityQueue} from '../priority-queue';
import type {HeapOptions} from '../../types';
-export class HeapItem {
+export class HeapItem {
/**
* The constructor function initializes an instance of a class with a priority and a value.
* @param {number} priority - The `priority` parameter is a number that represents the priority of the value. It is
* optional and has a default value of `NaN`.
- * @param {T | null} [val=null] - The `val` parameter is of type `T | null`, which means it can accept a value of type
- * `T` or `null`.
+ * @param {V | null} [val=null] - The `val` parameter is of type `V | null`, which means it can accept a value of type
+ * `V` or `null`.
*/
- constructor(priority: number = Number.MAX_SAFE_INTEGER, val: T | null = null) {
+ constructor(priority: number = Number.MAX_SAFE_INTEGER, val: V | null = null) {
this._val = val;
this._priority = priority;
}
@@ -31,24 +31,24 @@ export class HeapItem {
this._priority = value;
}
- private _val: T | null;
+ private _val: V | null;
- get val(): T | null {
+ get val(): V | null {
return this._val;
}
- set val(value: T | null) {
+ set val(value: V | null) {
this._val = value;
}
}
-export abstract class Heap {
+export abstract class Heap {
/**
* The function is a constructor for a class that initializes a priority callback function based on the
* options provided.
* @param [options] - An optional object that contains configuration options for the Heap.
*/
- protected constructor(options?: HeapOptions) {
+ protected constructor(options?: HeapOptions) {
if (options) {
const {priorityExtractor} = options;
if (priorityExtractor !== undefined && typeof priorityExtractor !== 'function') {
@@ -60,13 +60,13 @@ export abstract class Heap {
}
}
- protected abstract _pq: PriorityQueue>;
+ protected abstract _pq: PriorityQueue>;
get pq() {
return this._pq;
}
- protected _priorityExtractor: (val: T) => number;
+ protected _priorityExtractor: (val: V) => number;
get priorityExtractor() {
return this._priorityExtractor;
}
@@ -87,30 +87,30 @@ export abstract class Heap {
return this._pq.size < 1;
}
- peek(isItem?: undefined): T | undefined;
- peek(isItem: false): T | undefined;
- peek(isItem: true): HeapItem | null;
+ peek(isItem?: undefined): V | undefined;
+ peek(isItem: false): V | undefined;
+ peek(isItem: true): HeapItem | null;
/**
* The `peek` function returns the top item in the priority queue without removing it.
- * @returns The `peek()` method is returning either a `HeapItem` object or `null`.Returns an val with the highest priority in the queue
+ * @returns The `peek()` method is returning either a `HeapItem` object or `null`.Returns an val with the highest priority in the queue
*/
- peek(isItem?: boolean): HeapItem | null | T | undefined {
+ peek(isItem?: boolean): HeapItem | null | V | undefined {
isItem = isItem ?? false;
const peeked = this._pq.peek();
return isItem ? peeked : peeked?.val;
}
- peekLast(isItem?: undefined): T | undefined;
- peekLast(isItem: false): T | undefined;
- peekLast(isItem: true): HeapItem | null;
+ peekLast(isItem?: undefined): V | undefined;
+ peekLast(isItem: false): V | undefined;
+ peekLast(isItem: true): HeapItem | null;
/**
* The `peekLast` function returns the last item in the heap.
- * @returns The method `peekLast()` returns either a `HeapItem` object or `null`.Returns an val with the lowest priority in the queue
+ * @returns The method `peekLast()` returns either a `HeapItem` object or `null`.Returns an val with the lowest priority in the queue
*/
- peekLast(isItem?: boolean): HeapItem | null | T | undefined {
+ peekLast(isItem?: boolean): HeapItem | null | V | undefined {
isItem = isItem ?? false;
const leafItem = this._pq.leaf();
@@ -119,7 +119,7 @@ export abstract class Heap {
/**
* The `add` function adds an val to a priority queue with an optional priority value.
- * @param {T} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
+ * @param {V} val - The `val` parameter represents the value that you want to add to the heap. It can be of any
* type.
* @param {number} [priority] - The `priority` parameter is an optional number that represents the priority of the
* val being added to the heap. If the `val` parameter is a number, then the `priority` parameter is set to
@@ -127,22 +127,22 @@ export abstract class Heap {
* @returns The `add` method returns the instance of the `Heap` class.
* @throws {Error} if priority is not a valid number
*/
- add(priority: number, val?: T): Heap {
- val = val === undefined ? (priority as unknown as T) : val;
- this._pq.add(new HeapItem(priority, val));
+ add(priority: number, val?: V): Heap {
+ val = val === undefined ? (priority as unknown as V) : val;
+ this._pq.add(new HeapItem(priority, val));
return this;
}
- poll(isItem?: undefined): T | undefined;
- poll(isItem: false): T | undefined;
- poll(isItem: true): HeapItem | null;
+ poll(isItem?: undefined): V | undefined;
+ poll(isItem: false): V | undefined;
+ poll(isItem: true): HeapItem | null;
/**
* The `poll` function returns the top item from a priority queue or null if the queue is empty.Removes and returns an val with the highest priority in the queue
- * @returns either a HeapItem object or null.
+ * @returns either a HeapItem object or null.
*/
- poll(isItem?: boolean): HeapItem | null | T | undefined {
+ poll(isItem?: boolean): HeapItem | null | V | undefined {
isItem = isItem ?? false;
const top = this._pq.poll();
if (!top) {
@@ -154,10 +154,10 @@ export abstract class Heap {
/**
* The function checks if a given node or value exists in the priority queue.
- * @param {T | HeapItem} node - The parameter `node` can be of type `T` or `HeapItem`.
+ * @param {V | HeapItem} node - The parameter `node` can be of type `V` or `HeapItem`.
* @returns a boolean value.
*/
- has(node: T | HeapItem): boolean {
+ has(node: V | HeapItem): boolean {
if (node instanceof HeapItem) {
return this.pq.getNodes().includes(node);
} else {
@@ -169,34 +169,34 @@ export abstract class Heap {
}
}
- toArray(isItem?: undefined): (T | undefined)[];
- toArray(isItem: false): (T | undefined)[];
- toArray(isItem: true): (HeapItem | null)[];
+ toArray(isItem?: undefined): (V | undefined)[];
+ toArray(isItem: false): (V | undefined)[];
+ toArray(isItem: true): (HeapItem | null)[];
/**
- * The `toArray` function returns an array of `HeapItem` objects.
- * @returns An array of HeapItem objects.Returns a sorted list of vals
+ * The `toArray` function returns an array of `HeapItem` objects.
+ * @returns An array of HeapItem objects.Returns a sorted list of vals
*/
- toArray(isItem?: boolean): (HeapItem | null | T | undefined)[] {
+ toArray(isItem?: boolean): (HeapItem | null | V | undefined)[] {
isItem = isItem ?? false;
const itemArray = this._pq.toArray();
return isItem ? itemArray : itemArray.map(item => item.val);
}
- sort(isItem?: undefined): (T | undefined)[];
- sort(isItem: false): (T | undefined)[];
- sort(isItem: true): (HeapItem | null)[];
+ sort(isItem?: undefined): (V | undefined)[];
+ sort(isItem: false): (V | undefined)[];
+ sort(isItem: true): (HeapItem | null)[];
/**
* The function sorts the elements in the priority queue and returns either the sorted items or their values depending
* on the value of the isItem parameter.
* @param {boolean} [isItem] - The `isItem` parameter is a boolean flag that indicates whether the sorted result should
- * be an array of `HeapItem` objects or an array of the values (`T`) of those objects. If `isItem` is `true`, the
+ * be an array of `HeapItem` objects or an array of the values (`V`) of those objects. If `isItem` is `true`, the
* sorted result will be an array of `HeapItem
- * @returns an array of either `HeapItem`, `null`, `T`, or `undefined` values.
+ * @returns an array of either `HeapItem`, `null`, `V`, or `undefined` values.
*/
- sort(isItem?: boolean): (HeapItem | null | T | undefined)[] {
+ sort(isItem?: boolean): (HeapItem | null | V | undefined)[] {
isItem = isItem ?? false;
const sorted = this._pq.sort();
diff --git a/src/data-structures/heap/max-heap.ts b/src/data-structures/heap/max-heap.ts
index 48a72bd..2cba757 100644
--- a/src/data-structures/heap/max-heap.ts
+++ b/src/data-structures/heap/max-heap.ts
@@ -14,17 +14,17 @@ import type {HeapOptions} from '../../types';
* @class MaxHeap
* @extends Heap
*/
-export class MaxHeap extends Heap {
- protected _pq: PriorityQueue>;
+export class MaxHeap extends Heap {
+ protected _pq: PriorityQueue>;
/**
* The constructor initializes a PriorityQueue with a custom comparator function.
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
- * type `HeapOptions`, which is a generic type that represents the options for the heap.
+ * type `HeapOptions`, which is a generic type that represents the options for the heap.
*/
- constructor(options?: HeapOptions) {
+ constructor(options?: HeapOptions) {
super(options);
- this._pq = new PriorityQueue>({
+ this._pq = new PriorityQueue>({
comparator: (a, b) => b.priority - a.priority
});
}
diff --git a/src/data-structures/heap/min-heap.ts b/src/data-structures/heap/min-heap.ts
index 7c39209..11cb62e 100644
--- a/src/data-structures/heap/min-heap.ts
+++ b/src/data-structures/heap/min-heap.ts
@@ -14,18 +14,18 @@ import type {HeapOptions} from '../../types';
* @class MinHeap
* @extends Heap
*/
-export class MinHeap extends Heap {
- protected _pq: PriorityQueue>;
+export class MinHeap extends Heap {
+ protected _pq: PriorityQueue>;
/**
* The constructor initializes a PriorityQueue with a comparator function that compares the priority of two HeapItem
* objects.
* @param [options] - The `options` parameter is an optional object that can be passed to the constructor. It is of
- * type `HeapOptions`, which is a generic type that represents the options for the heap.
+ * type `HeapOptions`, which is a generic type that represents the options for the heap.
*/
- constructor(options?: HeapOptions) {
+ constructor(options?: HeapOptions) {
super(options);
- this._pq = new PriorityQueue>({
+ this._pq = new PriorityQueue>({
comparator: (a, b) => a.priority - b.priority
});
}
diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts
index cada302..ecf2f95 100644
--- a/src/data-structures/linked-list/doubly-linked-list.ts
+++ b/src/data-structures/linked-list/doubly-linked-list.ts
@@ -5,50 +5,50 @@
* @copyright Copyright (c) 2022 Tyler Zeng
* @license MIT License
*/
-export class DoublyLinkedListNode {
+export class DoublyLinkedListNode {
/**
* The constructor function initializes the value, next, and previous properties of an object.
- * @param {T} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
- * is defined as a generic type "T".
+ * @param {E} val - The "val" parameter is the value that will be stored in the node. It can be of any data type, as it
+ * is defined as a generic type "E".
*/
- constructor(val: T) {
+ constructor(val: E) {
this._val = val;
this._next = null;
this._prev = null;
}
- private _val: T;
+ private _val: E;
- get val(): T {
+ get val(): E {
return this._val;
}
- set val(value: T) {
+ set val(value: E) {
this._val = value;
}
- private _next: DoublyLinkedListNode | null;
+ private _next: DoublyLinkedListNode | null;
- get next(): DoublyLinkedListNode | null {
+ get next(): DoublyLinkedListNode | null {
return this._next;
}
- set next(value: DoublyLinkedListNode | null) {
+ set next(value: DoublyLinkedListNode | null) {
this._next = value;
}
- private _prev: DoublyLinkedListNode | null;
+ private _prev: DoublyLinkedListNode | null;
- get prev(): DoublyLinkedListNode | null {
+ get prev(): DoublyLinkedListNode | null {
return this._prev;
}
- set prev(value: DoublyLinkedListNode | null) {
+ set prev(value: DoublyLinkedListNode | null) {
this._prev = value;
}
}
-export class DoublyLinkedList {
+export class DoublyLinkedList {
/**
* The constructor initializes the linked list with an empty head, tail, and length.
*/
@@ -58,23 +58,23 @@ export class DoublyLinkedList {
this._length = 0;
}
- private _head: DoublyLinkedListNode | null;
+ private _head: DoublyLinkedListNode | null;
- get head(): DoublyLinkedListNode | null {
+ get head(): DoublyLinkedListNode | null {
return this._head;
}
- set head(value: DoublyLinkedListNode | null) {
+ set head(value: DoublyLinkedListNode | null) {
this._head = value;
}
- private _tail: DoublyLinkedListNode | null;
+ private _tail: DoublyLinkedListNode | null;
- get tail(): DoublyLinkedListNode | null {
+ get tail(): DoublyLinkedListNode | null {
return this._tail;
}
- set tail(value: DoublyLinkedListNode | null) {
+ set tail(value: DoublyLinkedListNode | null) {
this._tail = value;
}
@@ -87,11 +87,11 @@ export class DoublyLinkedList {
/**
* The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
* given array.
- * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
* @returns The `fromArray` function returns a DoublyLinkedList object.
*/
- static fromArray(data: T[]) {
- const doublyLinkedList = new DoublyLinkedList();
+ static fromArray(data: E[]) {
+ const doublyLinkedList = new DoublyLinkedList();
for (const item of data) {
doublyLinkedList.push(item);
}
@@ -100,9 +100,9 @@ export class DoublyLinkedList {
/**
* The push function adds a new node with the given value to the end of the doubly linked list.
- * @param {T} val - The value to be added to the linked list.
+ * @param {E} val - The value to be added to the linked list.
*/
- push(val: T): void {
+ push(val: E): void {
const newNode = new DoublyLinkedListNode(val);
if (!this.head) {
this.head = newNode;
@@ -120,7 +120,7 @@ export class DoublyLinkedList {
* @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
* list is empty, it returns null.
*/
- pop(): T | undefined {
+ pop(): E | undefined {
if (!this.tail) return undefined;
const removedNode = this.tail;
if (this.head === this.tail) {
@@ -139,7 +139,7 @@ export class DoublyLinkedList {
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
* list.
*/
- shift(): T | undefined {
+ shift(): E | undefined {
if (!this.head) return undefined;
const removedNode = this.head;
if (this.head === this.tail) {
@@ -155,10 +155,10 @@ export class DoublyLinkedList {
/**
* The unshift function adds a new node with the given value to the beginning of a doubly linked list.
- * @param {T} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
+ * @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
* doubly linked list.
*/
- unshift(val: T): void {
+ unshift(val: E): void {
const newNode = new DoublyLinkedListNode(val);
if (!this.head) {
this.head = newNode;
@@ -178,7 +178,7 @@ export class DoublyLinkedList {
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
* or the linked list is empty, it will return null.
*/
- getAt(index: number): T | undefined {
+ getAt(index: number): E | undefined {
if (index < 0 || index >= this.length) return undefined;
let current = this.head;
for (let i = 0; i < index; i++) {
@@ -192,10 +192,10 @@ export class DoublyLinkedList {
* range.
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
* retrieve from the doubly linked list. It indicates the zero-based index of the node we want to access.
- * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode` object if the index is within the
+ * @returns The method `getNodeAt(index: number)` returns a `DoublyLinkedListNode` object if the index is within the
* valid range of the linked list, otherwise it returns `null`.
*/
- getNodeAt(index: number): DoublyLinkedListNode | null {
+ getNodeAt(index: number): DoublyLinkedListNode | null {
if (index < 0 || index >= this.length) return null;
let current = this.head;
for (let i = 0; i < index; i++) {
@@ -207,11 +207,11 @@ export class DoublyLinkedList {
/**
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
* node if found, otherwise it returns null.
- * @param {T} val - The `val` parameter is the value that we want to search for in the doubly linked list.
- * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode` if a node with the specified value `val`
+ * @param {E} val - The `val` parameter is the value that we want to search for in the doubly linked list.
+ * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode` if a node with the specified value `val`
* is found in the linked list. If no such node is found, it returns `null`.
*/
- findNode(val: T): DoublyLinkedListNode | null {
+ findNode(val: E): DoublyLinkedListNode | null {
let current = this.head;
while (current) {
@@ -228,12 +228,12 @@ export class DoublyLinkedList {
* The `insert` function inserts a value at a specified index in a doubly linked list.
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
* DoublyLinkedList. It is of type number.
- * @param {T} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
+ * @param {E} val - The `val` parameter represents the value that you want to insert into the Doubly Linked List at the
* specified index.
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
* if the index is out of bounds.
*/
- insertAt(index: number, val: T): boolean {
+ insertAt(index: number, val: E): boolean {
if (index < 0 || index > this.length) return false;
if (index === 0) {
this.unshift(val);
@@ -262,7 +262,7 @@ export class DoublyLinkedList {
* @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
* bounds.
*/
- deleteAt(index: number): T | undefined {
+ deleteAt(index: number): E | undefined {
if (index < 0 || index >= this.length) return undefined;
if (index === 0) return this.shift();
if (index === this.length - 1) return this.pop();
@@ -276,18 +276,18 @@ export class DoublyLinkedList {
return removedNode!.val;
}
- delete(valOrNode: T): boolean;
- delete(valOrNode: DoublyLinkedListNode): boolean;
+ delete(valOrNode: E): boolean;
+ delete(valOrNode: DoublyLinkedListNode): boolean;
/**
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
- * @param {T | DoublyLinkedListNode} valOrNode - The `valOrNode` parameter can accept either a value of type `T` or
- * a `DoublyLinkedListNode` object.
+ * @param {E | DoublyLinkedListNode} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
+ * a `DoublyLinkedListNode` object.
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
*/
- delete(valOrNode: T | DoublyLinkedListNode): boolean {
- let node: DoublyLinkedListNode | null;
+ delete(valOrNode: E | DoublyLinkedListNode): boolean {
+ let node: DoublyLinkedListNode | null;
if (valOrNode instanceof DoublyLinkedListNode) {
node = valOrNode;
@@ -314,10 +314,10 @@ export class DoublyLinkedList {
/**
* The `toArray` function converts a linked list into an array.
- * @returns The `toArray()` method is returning an array of type `T[]`.
+ * @returns The `toArray()` method is returning an array of type `E[]`.
*/
- toArray(): T[] {
- const array: T[] = [];
+ toArray(): E[] {
+ const array: E[] = [];
let current = this.head;
while (current) {
array.push(current.val);
@@ -337,12 +337,12 @@ export class DoublyLinkedList {
/**
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
- * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
+ * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
* the callback function. If no element satisfies the condition, it returns `null`.
*/
- find(callback: (val: T) => boolean): T | null {
+ find(callback: (val: E) => boolean): E | null {
let current = this.head;
while (current) {
if (callback(current.val)) {
@@ -355,12 +355,12 @@ export class DoublyLinkedList {
/**
* The function returns the index of the first occurrence of a given value in a linked list.
- * @param {T} val - The parameter `val` is of type `T`, which means it can be any data type. It represents the value
+ * @param {E} val - The parameter `val` is of type `E`, which means it can be any data type. It represents the value
* that we are searching for in the linked list.
* @returns The method `indexOf` returns the index of the first occurrence of the specified value `val` in the linked
* list. If the value is not found, it returns -1.
*/
- indexOf(val: T): number {
+ indexOf(val: E): number {
let index = 0;
let current = this.head;
while (current) {
@@ -376,12 +376,12 @@ export class DoublyLinkedList {
/**
* The `findLast` function iterates through a linked list from the last node to the first node and returns the last
* value that satisfies the given callback function, or null if no value satisfies the callback.
- * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
+ * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
* function is used to determine whether a given value satisfies a certain condition.
* @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
* the callback function. If no value satisfies the condition, it returns `null`.
*/
- findLast(callback: (val: T) => boolean): T | null {
+ findLast(callback: (val: E) => boolean): E | null {
let current = this.tail;
while (current) {
if (callback(current.val)) {
@@ -394,10 +394,10 @@ export class DoublyLinkedList {
/**
* The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
- * @returns The `toArrayReverse()` function returns an array of type `T[]`.
+ * @returns The `toArrayReverse()` function returns an array of type `E[]`.
*/
- toArrayReverse(): T[] {
- const array: T[] = [];
+ toArrayReverse(): E[] {
+ const array: E[] = [];
let current = this.tail;
while (current) {
array.push(current.val);
@@ -425,7 +425,7 @@ export class DoublyLinkedList {
* represents the value of the current node in the linked list, and the index argument represents the index of the
* current node in the linked list.
*/
- forEach(callback: (val: T, index: number) => void): void {
+ forEach(callback: (val: E, index: number) => void): void {
let current = this.head;
let index = 0;
while (current) {
@@ -438,12 +438,12 @@ export class DoublyLinkedList {
/**
* The `map` function takes a callback function and applies it to each element in the DoublyLinkedList, returning a new
* DoublyLinkedList with the transformed values.
- * @param callback - The callback parameter is a function that takes a value of type T (the type of values stored in
+ * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
* the original DoublyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
* DoublyLinkedList).
* @returns The `map` function is returning a new instance of `DoublyLinkedList` that contains the mapped values.
*/
- map(callback: (val: T) => U): DoublyLinkedList {
+ map(callback: (val: E) => U): DoublyLinkedList {
const mappedList = new DoublyLinkedList();
let current = this.head;
while (current) {
@@ -456,12 +456,12 @@ export class DoublyLinkedList {
/**
* The `filter` function iterates through a DoublyLinkedList and returns a new DoublyLinkedList containing only the
* elements that satisfy the given callback function.
- * @param callback - The `callback` parameter is a function that takes a value of type `T` and returns a boolean value.
+ * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
* It is used to determine whether a value should be included in the filtered list or not.
* @returns The filtered list, which is an instance of the DoublyLinkedList class.
*/
- filter(callback: (val: T) => boolean): DoublyLinkedList {
- const filteredList = new DoublyLinkedList();
+ filter(callback: (val: E) => boolean): DoublyLinkedList {
+ const filteredList = new DoublyLinkedList();
let current = this.head;
while (current) {
if (callback(current.val)) {
@@ -482,7 +482,7 @@ export class DoublyLinkedList {
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
* elements in the linked list.
*/
- reduce(callback: (accumulator: U, val: T) => U, initialValue: U): U {
+ reduce(callback: (accumulator: U, val: E) => U, initialValue: U): U {
let accumulator = initialValue;
let current = this.head;
while (current) {
@@ -492,19 +492,19 @@ export class DoublyLinkedList {
return accumulator;
}
- insertAfter(existingValueOrNode: T, newValue: T): boolean;
- insertAfter(existingValueOrNode: DoublyLinkedListNode