data-structure-typed 0.8.18 → 1.12.9
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.
- package/.dependency-cruiser.js +449 -0
- package/.idea/data-structure-typed.iml +2 -0
- package/.idea/modules.xml +1 -1
- package/README.md +298 -2
- package/dist/data-structures/binary-tree/aa-tree.js +5 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +58 -5
- package/dist/data-structures/binary-tree/avl-tree.js +150 -46
- package/dist/data-structures/binary-tree/b-tree.js +5 -2
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +28 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +41 -13
- package/dist/data-structures/binary-tree/binary-tree.d.ts +230 -36
- package/dist/data-structures/binary-tree/binary-tree.js +747 -369
- package/dist/data-structures/binary-tree/bst.d.ts +20 -8
- package/dist/data-structures/binary-tree/bst.js +164 -107
- package/dist/data-structures/binary-tree/rb-tree.js +5 -2
- package/dist/data-structures/binary-tree/segment-tree.d.ts +7 -3
- package/dist/data-structures/binary-tree/segment-tree.js +95 -61
- package/dist/data-structures/binary-tree/splay-tree.js +5 -2
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +5 -5
- package/dist/data-structures/binary-tree/tree-multiset.js +35 -11
- package/dist/data-structures/binary-tree/two-three-tree.js +5 -2
- package/dist/data-structures/graph/abstract-graph.d.ts +168 -46
- package/dist/data-structures/graph/abstract-graph.js +712 -323
- package/dist/data-structures/graph/directed-graph.d.ts +114 -12
- package/dist/data-structures/graph/directed-graph.js +372 -128
- package/dist/data-structures/graph/undirected-graph.d.ts +67 -3
- package/dist/data-structures/graph/undirected-graph.js +233 -81
- package/dist/data-structures/hash/coordinate-map.d.ts +33 -1
- package/dist/data-structures/hash/coordinate-map.js +70 -20
- package/dist/data-structures/hash/coordinate-set.d.ts +25 -0
- package/dist/data-structures/hash/coordinate-set.js +58 -15
- package/dist/data-structures/hash/index.d.ts +5 -0
- package/dist/data-structures/hash/index.js +5 -0
- package/dist/data-structures/heap/heap.d.ts +26 -37
- package/dist/data-structures/heap/heap.js +56 -60
- package/dist/data-structures/heap/max-heap.d.ts +8 -2
- package/dist/data-structures/heap/max-heap.js +32 -9
- package/dist/data-structures/heap/min-heap.d.ts +9 -2
- package/dist/data-structures/heap/min-heap.js +33 -9
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +14 -7
- package/dist/data-structures/linked-list/doubly-linked-list.js +101 -61
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +18 -19
- package/dist/data-structures/linked-list/singly-linked-list.js +312 -174
- package/dist/data-structures/matrix/matrix.d.ts +9 -0
- package/dist/data-structures/matrix/matrix.js +19 -7
- package/dist/data-structures/matrix/matrix2d.d.ts +84 -4
- package/dist/data-structures/matrix/matrix2d.js +158 -61
- package/dist/data-structures/matrix/navigator.d.ts +34 -16
- package/dist/data-structures/matrix/navigator.js +65 -18
- package/dist/data-structures/matrix/vector2d.d.ts +153 -29
- package/dist/data-structures/matrix/vector2d.js +249 -102
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/max-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -2
- package/dist/data-structures/priority-queue/min-priority-queue.js +33 -8
- package/dist/data-structures/priority-queue/priority-queue.d.ts +145 -21
- package/dist/data-structures/priority-queue/priority-queue.js +285 -116
- package/dist/data-structures/queue/deque.d.ts +69 -0
- package/dist/data-structures/queue/deque.js +151 -56
- package/dist/data-structures/queue/queue.d.ts +34 -37
- package/dist/data-structures/queue/queue.js +59 -61
- package/dist/data-structures/stack/stack.d.ts +29 -35
- package/dist/data-structures/stack/stack.js +51 -56
- package/dist/data-structures/trie/trie.d.ts +36 -6
- package/dist/data-structures/trie/trie.js +256 -83
- package/dist/data-structures/types/abstract-graph.d.ts +29 -0
- package/dist/data-structures/types/abstract-graph.js +2 -0
- package/dist/data-structures/types/avl-tree.d.ts +5 -0
- package/dist/data-structures/types/avl-tree.js +2 -0
- package/dist/data-structures/types/binary-tree.d.ts +16 -0
- package/dist/data-structures/types/binary-tree.js +2 -0
- package/dist/data-structures/types/bst.d.ts +7 -0
- package/dist/data-structures/types/bst.js +2 -0
- package/dist/data-structures/types/directed-graph.d.ts +10 -0
- package/dist/data-structures/types/directed-graph.js +2 -0
- package/dist/data-structures/types/doubly-linked-list.d.ts +1 -0
- package/dist/data-structures/types/doubly-linked-list.js +2 -0
- package/dist/data-structures/types/heap.d.ts +7 -0
- package/dist/data-structures/types/heap.js +2 -0
- package/dist/data-structures/types/index.d.ts +13 -0
- package/dist/data-structures/types/index.js +29 -0
- package/dist/data-structures/types/navigator.d.ts +14 -0
- package/dist/data-structures/types/navigator.js +2 -0
- package/dist/data-structures/types/priority-queue.d.ts +7 -0
- package/dist/data-structures/types/priority-queue.js +2 -0
- package/dist/data-structures/types/segment-tree.d.ts +1 -0
- package/dist/data-structures/types/segment-tree.js +2 -0
- package/dist/data-structures/types/singly-linked-list.js +2 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -0
- package/dist/data-structures/types/tree-multiset.js +2 -0
- package/dist/utils/trampoline.d.ts +14 -0
- package/dist/utils/trampoline.js +130 -0
- package/dist/utils/types/index.js +17 -0
- package/dist/{types → utils}/types/utils.d.ts +15 -1
- package/dist/{types → utils/types}/utils.js +21 -19
- package/dist/{utils.d.ts → utils/utils.d.ts} +5 -22
- package/dist/utils/utils.js +651 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/highlight.css +85 -0
- package/docs/assets/main.js +58 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1367 -0
- package/docs/classes/AVLTree.html +2046 -0
- package/docs/classes/AVLTreeNode.html +423 -0
- package/docs/classes/AaTree.html +117 -0
- package/docs/classes/AbstractEdge.html +198 -0
- package/docs/classes/AbstractGraph.html +891 -0
- package/docs/classes/AbstractVertex.html +164 -0
- package/docs/classes/ArrayDeque.html +384 -0
- package/docs/classes/BST.html +1893 -0
- package/docs/classes/BSTNode.html +425 -0
- package/docs/classes/BTree.html +117 -0
- package/docs/classes/BinaryIndexedTree.html +244 -0
- package/docs/classes/BinaryTree.html +1754 -0
- package/docs/classes/BinaryTreeNode.html +396 -0
- package/docs/classes/Character.html +165 -0
- package/docs/classes/CoordinateMap.html +394 -0
- package/docs/classes/CoordinateSet.html +355 -0
- package/docs/classes/Deque.html +617 -0
- package/docs/classes/DirectedEdge.html +247 -0
- package/docs/classes/DirectedGraph.html +1207 -0
- package/docs/classes/DirectedVertex.html +154 -0
- package/docs/classes/DoublyLinkedList.html +619 -0
- package/docs/classes/DoublyLinkedListNode.html +160 -0
- package/docs/classes/Heap.html +315 -0
- package/docs/classes/Matrix2D.html +447 -0
- package/docs/classes/MatrixNTI2D.html +181 -0
- package/docs/classes/MaxHeap.html +325 -0
- package/docs/classes/MaxPriorityQueue.html +668 -0
- package/docs/classes/MinHeap.html +326 -0
- package/docs/classes/MinPriorityQueue.html +668 -0
- package/docs/classes/Navigator.html +285 -0
- package/docs/classes/ObjectDeque.html +289 -0
- package/docs/classes/PriorityQueue.html +643 -0
- package/docs/classes/Queue.html +337 -0
- package/docs/classes/RBTree.html +117 -0
- package/docs/classes/SegmentTree.html +234 -0
- package/docs/classes/SegmentTreeNode.html +302 -0
- package/docs/classes/SinglyLinkedList.html +1035 -0
- package/docs/classes/SinglyLinkedListNode.html +304 -0
- package/docs/classes/SplayTree.html +117 -0
- package/docs/classes/Stack.html +313 -0
- package/docs/classes/TreeMultiSet.html +1897 -0
- package/docs/classes/Trie.html +317 -0
- package/docs/classes/TrieNode.html +221 -0
- package/docs/classes/TwoThreeTree.html +117 -0
- package/docs/classes/UndirectedEdge.html +220 -0
- package/docs/classes/UndirectedGraph.html +1006 -0
- package/docs/classes/UndirectedVertex.html +154 -0
- package/docs/classes/Vector2D.html +746 -0
- package/docs/enums/CP.html +126 -0
- package/docs/enums/FamilyPosition.html +126 -0
- package/docs/enums/LoopType.html +119 -0
- package/docs/index.html +288 -0
- package/docs/modules.html +146 -0
- package/jest.config.js +5 -0
- package/package.json +33 -47
- package/rename_clear_files.sh +29 -0
- package/src/assets/complexities-diff.jpg +0 -0
- package/src/assets/data-structure-complexities.jpg +0 -0
- package/src/data-structures/binary-tree/avl-tree.ts +58 -6
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +31 -4
- package/src/data-structures/binary-tree/binary-tree.ts +460 -145
- package/src/data-structures/binary-tree/bst.ts +31 -25
- package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/src/data-structures/binary-tree/segment-tree.ts +25 -12
- package/src/data-structures/binary-tree/tree-multiset.ts +5 -4
- package/src/data-structures/diagrams/README.md +5 -0
- package/src/data-structures/graph/abstract-graph.ts +224 -108
- package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/src/data-structures/graph/directed-graph.ts +132 -26
- package/src/data-structures/graph/undirected-graph.ts +78 -11
- package/src/data-structures/hash/coordinate-map.ts +33 -1
- package/src/data-structures/hash/coordinate-set.ts +25 -0
- package/src/data-structures/hash/index.ts +5 -0
- package/src/data-structures/heap/heap.ts +27 -41
- package/src/data-structures/heap/max-heap.ts +8 -2
- package/src/data-structures/heap/min-heap.ts +9 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -17
- package/src/data-structures/linked-list/singly-linked-list.ts +56 -39
- package/src/data-structures/matrix/matrix.ts +11 -0
- package/src/data-structures/matrix/matrix2d.ts +90 -10
- package/src/data-structures/matrix/navigator.ts +34 -14
- package/src/data-structures/matrix/vector2d.ts +187 -63
- package/src/data-structures/priority-queue/max-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +12 -3
- package/src/data-structures/priority-queue/priority-queue.ts +200 -78
- package/src/data-structures/queue/deque.ts +71 -2
- package/src/data-structures/queue/queue.ts +37 -40
- package/src/data-structures/stack/stack.ts +32 -38
- package/src/data-structures/trie/trie.ts +83 -14
- package/src/data-structures/types/abstract-graph.ts +51 -0
- package/src/data-structures/types/avl-tree.ts +6 -0
- package/src/data-structures/types/binary-tree.ts +15 -0
- package/src/data-structures/types/bst.ts +5 -0
- package/src/data-structures/types/directed-graph.ts +18 -0
- package/src/data-structures/types/doubly-linked-list.ts +1 -0
- package/src/data-structures/types/heap.ts +8 -0
- package/src/data-structures/types/index.ts +13 -0
- package/src/data-structures/types/navigator.ts +13 -0
- package/src/data-structures/types/priority-queue.ts +9 -0
- package/src/data-structures/types/segment-tree.ts +1 -0
- package/src/data-structures/types/singly-linked-list.ts +1 -0
- package/src/data-structures/types/tree-multiset.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/trampoline.ts +51 -0
- package/src/utils/types/index.ts +1 -0
- package/src/{types → utils/types}/utils.ts +27 -5
- package/src/{utils.ts → utils/utils.ts} +41 -131
- package/tests/unit/data-structures/binary-tree/bst.test.ts +185 -0
- package/tests/unit/data-structures/graph/directed-graph.test.ts +71 -0
- package/{dist/types/data-structures/graph/index.d.ts → tests/unit/data-structures/graph/index.ts} +1 -1
- package/tests/unit/data-structures/graph/undirected-graph.ts +0 -0
- package/tsconfig.json +9 -6
- package/dist/data-structures/trampoline.d.ts +0 -25
- package/dist/data-structures/trampoline.js +0 -52
- package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
- package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
- package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
- package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
- package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
- package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
- package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
- package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
- package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
- package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
- package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/pair.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-map.d.ts +0 -1
- package/dist/types/data-structures/hash/tree-set.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +0 -72
- package/dist/types/data-structures/heap/index.d.ts +0 -3
- package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
- package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
- package/dist/types/data-structures/index.d.ts +0 -9
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
- package/dist/types/data-structures/linked-list/index.d.ts +0 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +0 -1
- package/dist/types/data-structures/matrix/index.d.ts +0 -3
- package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
- package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
- package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
- package/dist/types/data-structures/queue/deque.d.ts +0 -37
- package/dist/types/data-structures/queue/index.d.ts +0 -1
- package/dist/types/data-structures/queue/queue.d.ts +0 -76
- package/dist/types/data-structures/stack/index.d.ts +0 -1
- package/dist/types/data-structures/stack/stack.d.ts +0 -69
- package/dist/types/data-structures/trampoline.d.ts +0 -25
- package/dist/types/data-structures/trie/index.d.ts +0 -1
- package/dist/types/data-structures/trie/trie.d.ts +0 -28
- package/dist/types/utils.d.ts +0 -46
- package/dist/utils.js +0 -569
- package/src/data-structures/trampoline.ts +0 -91
- package/src/types/index.ts +0 -1
- /package/dist/{types/data-structures/hash/hash-table.d.ts → data-structures/types/singly-linked-list.d.ts} +0 -0
- /package/dist/{types → utils}/index.d.ts +0 -0
- /package/dist/{types → utils}/index.js +0 -0
- /package/dist/{types → utils}/types/index.d.ts +0 -0
- /package/{src/types/patches/index.d.ts → tests/unit/data-structures/graph/abstract-graph.ts} +0 -0
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.ArrayDeque = exports.ObjectDeque = exports.Deque = void 0;
|
|
4
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
21
|
+
* @license MIT
|
|
22
|
+
*/
|
|
23
|
+
var linked_list_1 = require("../linked-list");
|
|
5
24
|
// O(n) time complexity of obtaining the value
|
|
6
25
|
// O(1) time complexity of adding at the beginning and the end
|
|
7
|
-
|
|
8
|
-
|
|
26
|
+
var Deque = /** @class */ (function (_super) {
|
|
27
|
+
__extends(Deque, _super);
|
|
28
|
+
function Deque() {
|
|
29
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
30
|
+
}
|
|
31
|
+
return Deque;
|
|
32
|
+
}(linked_list_1.DoublyLinkedList));
|
|
9
33
|
exports.Deque = Deque;
|
|
10
34
|
// O(1) time complexity of obtaining the value
|
|
11
35
|
// O(n) time complexity of adding at the beginning and the end
|
|
12
36
|
// todo tested slowest one
|
|
13
|
-
|
|
14
|
-
|
|
37
|
+
var ObjectDeque = /** @class */ (function () {
|
|
38
|
+
function ObjectDeque(capacity) {
|
|
15
39
|
this._nodes = {};
|
|
16
40
|
this._capacity = Number.MAX_SAFE_INTEGER;
|
|
17
41
|
this._first = -1;
|
|
@@ -20,12 +44,12 @@ class ObjectDeque {
|
|
|
20
44
|
if (capacity !== undefined)
|
|
21
45
|
this._capacity = capacity;
|
|
22
46
|
}
|
|
23
|
-
size() {
|
|
47
|
+
ObjectDeque.prototype.size = function () {
|
|
24
48
|
return this._size;
|
|
25
|
-
}
|
|
26
|
-
offerFirst(value) {
|
|
49
|
+
};
|
|
50
|
+
ObjectDeque.prototype.offerFirst = function (value) {
|
|
27
51
|
if (this._size === 0) {
|
|
28
|
-
|
|
52
|
+
var mid = Math.floor(this._capacity / 2);
|
|
29
53
|
this._first = mid;
|
|
30
54
|
this._last = mid;
|
|
31
55
|
}
|
|
@@ -34,10 +58,10 @@ class ObjectDeque {
|
|
|
34
58
|
}
|
|
35
59
|
this._nodes[this._first] = value;
|
|
36
60
|
this._size++;
|
|
37
|
-
}
|
|
38
|
-
offerLast(value) {
|
|
61
|
+
};
|
|
62
|
+
ObjectDeque.prototype.offerLast = function (value) {
|
|
39
63
|
if (this._size === 0) {
|
|
40
|
-
|
|
64
|
+
var mid = Math.floor(this._capacity / 2);
|
|
41
65
|
this._first = mid;
|
|
42
66
|
this._last = mid;
|
|
43
67
|
}
|
|
@@ -46,87 +70,158 @@ class ObjectDeque {
|
|
|
46
70
|
}
|
|
47
71
|
this._nodes[this._last] = value;
|
|
48
72
|
this._size++;
|
|
49
|
-
}
|
|
50
|
-
pollFirst() {
|
|
73
|
+
};
|
|
74
|
+
ObjectDeque.prototype.pollFirst = function () {
|
|
51
75
|
if (!this._size)
|
|
52
76
|
return;
|
|
53
|
-
|
|
77
|
+
var value = this.peekFirst();
|
|
54
78
|
delete this._nodes[this._first];
|
|
55
79
|
this._first++;
|
|
56
80
|
this._size--;
|
|
57
81
|
return value;
|
|
58
|
-
}
|
|
59
|
-
peekFirst() {
|
|
82
|
+
};
|
|
83
|
+
ObjectDeque.prototype.peekFirst = function () {
|
|
60
84
|
if (this._size)
|
|
61
85
|
return this._nodes[this._first];
|
|
62
|
-
}
|
|
63
|
-
pollLast() {
|
|
86
|
+
};
|
|
87
|
+
ObjectDeque.prototype.pollLast = function () {
|
|
64
88
|
if (!this._size)
|
|
65
89
|
return;
|
|
66
|
-
|
|
90
|
+
var value = this.peekLast();
|
|
67
91
|
delete this._nodes[this._last];
|
|
68
92
|
this._last--;
|
|
69
93
|
this._size--;
|
|
70
94
|
return value;
|
|
71
|
-
}
|
|
72
|
-
peekLast() {
|
|
95
|
+
};
|
|
96
|
+
ObjectDeque.prototype.peekLast = function () {
|
|
73
97
|
if (this._size)
|
|
74
98
|
return this._nodes[this._last];
|
|
75
|
-
}
|
|
76
|
-
get(index) {
|
|
99
|
+
};
|
|
100
|
+
ObjectDeque.prototype.get = function (index) {
|
|
77
101
|
return this._nodes[this._first + index] || null;
|
|
78
|
-
}
|
|
79
|
-
isEmpty() {
|
|
102
|
+
};
|
|
103
|
+
ObjectDeque.prototype.isEmpty = function () {
|
|
80
104
|
return this._size <= 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
105
|
+
};
|
|
106
|
+
return ObjectDeque;
|
|
107
|
+
}());
|
|
83
108
|
exports.ObjectDeque = ObjectDeque;
|
|
84
109
|
// O(1) time complexity of obtaining the value
|
|
85
110
|
// O(n) time complexity of adding at the beginning and the end
|
|
86
|
-
|
|
87
|
-
|
|
111
|
+
var ArrayDeque = /** @class */ (function () {
|
|
112
|
+
function ArrayDeque() {
|
|
88
113
|
this._nodes = [];
|
|
89
114
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
115
|
+
Object.defineProperty(ArrayDeque.prototype, "size", {
|
|
116
|
+
get: function () {
|
|
117
|
+
return this._nodes.length;
|
|
118
|
+
},
|
|
119
|
+
enumerable: false,
|
|
120
|
+
configurable: true
|
|
121
|
+
});
|
|
122
|
+
/**
|
|
123
|
+
* The function "offerLast" adds a value to the end of an array.
|
|
124
|
+
* @param {T} value - The value parameter represents the value that you want to add to the end of the array.
|
|
125
|
+
* @returns The return value is the new length of the array after the value has been added.
|
|
126
|
+
*/
|
|
127
|
+
ArrayDeque.prototype.offerLast = function (value) {
|
|
94
128
|
return this._nodes.push(value);
|
|
95
|
-
}
|
|
96
|
-
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
|
|
132
|
+
* @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
|
|
133
|
+
*/
|
|
134
|
+
ArrayDeque.prototype.pollLast = function () {
|
|
97
135
|
var _a;
|
|
98
136
|
return (_a = this._nodes.pop()) !== null && _a !== void 0 ? _a : null;
|
|
99
|
-
}
|
|
100
|
-
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
|
|
140
|
+
* @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
|
|
141
|
+
* empty.
|
|
142
|
+
*/
|
|
143
|
+
ArrayDeque.prototype.pollFirst = function () {
|
|
101
144
|
var _a;
|
|
102
145
|
return (_a = this._nodes.shift()) !== null && _a !== void 0 ? _a : null;
|
|
103
|
-
}
|
|
104
|
-
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The function "offerFirst" adds a value to the beginning of an array.
|
|
149
|
+
* @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
|
|
150
|
+
* @returns The return value of the `offerFirst` function is the new length of the array `_nodes` after adding the
|
|
151
|
+
* `value` at the beginning.
|
|
152
|
+
*/
|
|
153
|
+
ArrayDeque.prototype.offerFirst = function (value) {
|
|
105
154
|
return this._nodes.unshift(value);
|
|
106
|
-
}
|
|
107
|
-
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* The `peekFirst` function returns the first element of an array or null if the array is empty.
|
|
158
|
+
* @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
|
|
159
|
+
* empty, it will return `null`.
|
|
160
|
+
*/
|
|
161
|
+
ArrayDeque.prototype.peekFirst = function () {
|
|
108
162
|
var _a;
|
|
109
163
|
return (_a = this._nodes[0]) !== null && _a !== void 0 ? _a : null;
|
|
110
|
-
}
|
|
111
|
-
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* The `peekLast` function returns the last element of an array or null if the array is empty.
|
|
167
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
|
|
168
|
+
*/
|
|
169
|
+
ArrayDeque.prototype.peekLast = function () {
|
|
112
170
|
var _a;
|
|
113
171
|
return (_a = this._nodes[this._nodes.length - 1]) !== null && _a !== void 0 ? _a : null;
|
|
114
|
-
}
|
|
115
|
-
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* The get function returns the element at the specified index in an array, or null if the index is out of bounds.
|
|
175
|
+
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
176
|
+
* retrieve from the array.
|
|
177
|
+
* @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
|
|
178
|
+
* will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
|
|
179
|
+
*/
|
|
180
|
+
ArrayDeque.prototype.get = function (index) {
|
|
116
181
|
var _a;
|
|
117
182
|
return (_a = this._nodes[index]) !== null && _a !== void 0 ? _a : null;
|
|
118
|
-
}
|
|
119
|
-
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* The set function assigns a value to a specific index in an array.
|
|
186
|
+
* @param {number} index - The index parameter is a number that represents the position of the element in the array
|
|
187
|
+
* that you want to set a new value for.
|
|
188
|
+
* @param {T} value - The value parameter represents the new value that you want to set at the specified index in the
|
|
189
|
+
* _nodes array.
|
|
190
|
+
* @returns The value that is being set at the specified index in the `_nodes` array.
|
|
191
|
+
*/
|
|
192
|
+
ArrayDeque.prototype.set = function (index, value) {
|
|
120
193
|
return this._nodes[index] = value;
|
|
121
|
-
}
|
|
122
|
-
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* The insert function adds a value at a specified index in an array.
|
|
197
|
+
* @param {number} index - The index parameter specifies the position at which the value should be inserted in the
|
|
198
|
+
* array. It is a number that represents the index of the array where the value should be inserted. The index starts
|
|
199
|
+
* from 0, so the first element of the array has an index of 0, the second element has
|
|
200
|
+
* @param {T} value - The value parameter represents the value that you want to insert into the array at the specified
|
|
201
|
+
* index.
|
|
202
|
+
* @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
|
|
203
|
+
* are being removed, an empty array will be returned.
|
|
204
|
+
*/
|
|
205
|
+
ArrayDeque.prototype.insert = function (index, value) {
|
|
123
206
|
return this._nodes.splice(index, 0, value);
|
|
124
|
-
}
|
|
125
|
-
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* The remove function removes an element from an array at a specified index.
|
|
210
|
+
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
|
|
211
|
+
* is a number that represents the index of the element to be removed.
|
|
212
|
+
* @returns The method is returning an array containing the removed element.
|
|
213
|
+
*/
|
|
214
|
+
ArrayDeque.prototype.remove = function (index) {
|
|
126
215
|
return this._nodes.splice(index, 1);
|
|
127
|
-
}
|
|
128
|
-
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* The function checks if an array called "_nodes" is empty.
|
|
219
|
+
* @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
|
|
220
|
+
* is 0, indicating that the array is empty. Otherwise, it returns `false`.
|
|
221
|
+
*/
|
|
222
|
+
ArrayDeque.prototype.isEmpty = function () {
|
|
129
223
|
return this._nodes.length === 0;
|
|
130
|
-
}
|
|
131
|
-
|
|
224
|
+
};
|
|
225
|
+
return ArrayDeque;
|
|
226
|
+
}());
|
|
132
227
|
exports.ArrayDeque = ArrayDeque;
|
|
@@ -1,76 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license MIT
|
|
3
|
-
* @copyright
|
|
4
|
-
*
|
|
3
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
5
4
|
* @class
|
|
6
5
|
*/
|
|
7
6
|
export declare class Queue<T> {
|
|
8
7
|
protected _nodes: T[];
|
|
9
8
|
protected _offset: number;
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
12
|
-
* @param {
|
|
10
|
+
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
11
|
+
* @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
|
|
12
|
+
* will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
|
|
13
|
+
* initialized as an empty array.
|
|
13
14
|
*/
|
|
14
15
|
constructor(elements?: T[]);
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
17
18
|
* @public
|
|
18
|
-
* @
|
|
19
|
+
* @static
|
|
20
|
+
* @param {T[]} elements - The "elements" parameter is an array of elements of type T.
|
|
21
|
+
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
22
|
+
* array.
|
|
23
|
+
*/
|
|
24
|
+
static fromArray<T>(elements: T[]): Queue<T>;
|
|
25
|
+
/**
|
|
26
|
+
* The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
27
|
+
* @param {T} element - The `element` parameter represents the element that you want to add to the queue.
|
|
28
|
+
* @returns The `offer` method is returning a `Queue<T>` object.
|
|
19
29
|
*/
|
|
20
30
|
offer(element: T): Queue<T>;
|
|
21
31
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @returns
|
|
32
|
+
* The `poll` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
33
|
+
* necessary to optimize performance.
|
|
34
|
+
* @returns The function `poll()` returns either the first element in the queue or `null` if the queue is empty.
|
|
25
35
|
*/
|
|
26
36
|
poll(): T | null;
|
|
27
37
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @
|
|
30
|
-
*
|
|
38
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
39
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
40
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
31
41
|
*/
|
|
32
42
|
peek(): T | null;
|
|
33
43
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
44
|
+
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
45
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
46
|
+
* array is empty, it returns `null`.
|
|
37
47
|
*/
|
|
38
48
|
peekLast(): T | null;
|
|
39
49
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @
|
|
42
|
-
* @returns {number}
|
|
50
|
+
* The size function returns the number of elements in an array.
|
|
51
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
43
52
|
*/
|
|
44
53
|
size(): number;
|
|
45
54
|
/**
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
* @returns {boolean}
|
|
55
|
+
* The function checks if a data structure is empty by comparing its size to zero.
|
|
56
|
+
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
49
57
|
*/
|
|
50
58
|
isEmpty(): boolean;
|
|
51
59
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
54
|
-
* @returns {array}
|
|
60
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
|
|
61
|
+
* @returns An array of type T is being returned.
|
|
55
62
|
*/
|
|
56
63
|
toArray(): T[];
|
|
57
64
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @public
|
|
65
|
+
* The clear function resets the nodes array and offset to their initial values.
|
|
60
66
|
*/
|
|
61
67
|
clear(): void;
|
|
62
68
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
* @return {Queue}
|
|
69
|
+
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
70
|
+
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
66
71
|
*/
|
|
67
72
|
clone(): Queue<T>;
|
|
68
|
-
/**
|
|
69
|
-
* Creates a queue from an existing array.
|
|
70
|
-
* @public
|
|
71
|
-
* @static
|
|
72
|
-
* @param {array} elements
|
|
73
|
-
* @return {Queue}
|
|
74
|
-
*/
|
|
75
|
-
static fromArray<T>(elements: T[]): Queue<T>;
|
|
76
73
|
}
|
|
@@ -3,37 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Queue = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @license MIT
|
|
6
|
-
* @copyright
|
|
7
|
-
*
|
|
6
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
8
7
|
* @class
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
var Queue = /** @class */ (function () {
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {
|
|
11
|
+
* The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
|
|
12
|
+
* @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
|
|
13
|
+
* will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
|
|
14
|
+
* initialized as an empty array.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
function Queue(elements) {
|
|
16
17
|
this._nodes = elements || [];
|
|
17
18
|
this._offset = 0;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
21
22
|
* @public
|
|
22
|
-
* @
|
|
23
|
+
* @static
|
|
24
|
+
* @param {T[]} elements - The "elements" parameter is an array of elements of type T.
|
|
25
|
+
* @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
|
|
26
|
+
* array.
|
|
27
|
+
*/
|
|
28
|
+
Queue.fromArray = function (elements) {
|
|
29
|
+
return new Queue(elements);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The offer function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
33
|
+
* @param {T} element - The `element` parameter represents the element that you want to add to the queue.
|
|
34
|
+
* @returns The `offer` method is returning a `Queue<T>` object.
|
|
23
35
|
*/
|
|
24
|
-
offer(element) {
|
|
36
|
+
Queue.prototype.offer = function (element) {
|
|
25
37
|
this._nodes.push(element);
|
|
26
38
|
return this;
|
|
27
|
-
}
|
|
39
|
+
};
|
|
28
40
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @returns
|
|
41
|
+
* The `poll` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
42
|
+
* necessary to optimize performance.
|
|
43
|
+
* @returns The function `poll()` returns either the first element in the queue or `null` if the queue is empty.
|
|
32
44
|
*/
|
|
33
|
-
poll() {
|
|
45
|
+
Queue.prototype.poll = function () {
|
|
34
46
|
if (this.size() === 0)
|
|
35
47
|
return null;
|
|
36
|
-
|
|
48
|
+
var first = this.peek();
|
|
37
49
|
this._offset += 1;
|
|
38
50
|
if (this._offset * 2 < this._nodes.length)
|
|
39
51
|
return first;
|
|
@@ -42,72 +54,58 @@ class Queue {
|
|
|
42
54
|
this._nodes = this._nodes.slice(this._offset);
|
|
43
55
|
this._offset = 0;
|
|
44
56
|
return first;
|
|
45
|
-
}
|
|
57
|
+
};
|
|
46
58
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
49
|
-
*
|
|
59
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
|
|
60
|
+
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
61
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
|
|
50
62
|
*/
|
|
51
|
-
peek() {
|
|
63
|
+
Queue.prototype.peek = function () {
|
|
52
64
|
return this.size() > 0 ? this._nodes[this._offset] : null;
|
|
53
|
-
}
|
|
65
|
+
};
|
|
54
66
|
/**
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
*
|
|
67
|
+
* The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
|
|
68
|
+
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
69
|
+
* array is empty, it returns `null`.
|
|
58
70
|
*/
|
|
59
|
-
peekLast() {
|
|
71
|
+
Queue.prototype.peekLast = function () {
|
|
60
72
|
return this.size() > 0 ? this._nodes[this._nodes.length - 1] : null;
|
|
61
|
-
}
|
|
73
|
+
};
|
|
62
74
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @
|
|
65
|
-
* @returns {number}
|
|
75
|
+
* The size function returns the number of elements in an array.
|
|
76
|
+
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
66
77
|
*/
|
|
67
|
-
size() {
|
|
78
|
+
Queue.prototype.size = function () {
|
|
68
79
|
return this._nodes.length - this._offset;
|
|
69
|
-
}
|
|
80
|
+
};
|
|
70
81
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
73
|
-
* @returns {boolean}
|
|
82
|
+
* The function checks if a data structure is empty by comparing its size to zero.
|
|
83
|
+
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
74
84
|
*/
|
|
75
|
-
isEmpty() {
|
|
85
|
+
Queue.prototype.isEmpty = function () {
|
|
76
86
|
return this.size() === 0;
|
|
77
|
-
}
|
|
87
|
+
};
|
|
78
88
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @
|
|
81
|
-
* @returns {array}
|
|
89
|
+
* The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
|
|
90
|
+
* @returns An array of type T is being returned.
|
|
82
91
|
*/
|
|
83
|
-
toArray() {
|
|
92
|
+
Queue.prototype.toArray = function () {
|
|
84
93
|
return this._nodes.slice(this._offset);
|
|
85
|
-
}
|
|
94
|
+
};
|
|
86
95
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @public
|
|
96
|
+
* The clear function resets the nodes array and offset to their initial values.
|
|
89
97
|
*/
|
|
90
|
-
clear() {
|
|
98
|
+
Queue.prototype.clear = function () {
|
|
91
99
|
this._nodes = [];
|
|
92
100
|
this._offset = 0;
|
|
93
|
-
}
|
|
101
|
+
};
|
|
94
102
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @
|
|
97
|
-
* @return {Queue}
|
|
103
|
+
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
104
|
+
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
98
105
|
*/
|
|
99
|
-
clone() {
|
|
106
|
+
Queue.prototype.clone = function () {
|
|
100
107
|
return new Queue(this._nodes.slice(this._offset));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
* @public
|
|
105
|
-
* @static
|
|
106
|
-
* @param {array} elements
|
|
107
|
-
* @return {Queue}
|
|
108
|
-
*/
|
|
109
|
-
static fromArray(elements) {
|
|
110
|
-
return new Queue(elements);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
108
|
+
};
|
|
109
|
+
return Queue;
|
|
110
|
+
}());
|
|
113
111
|
exports.Queue = Queue;
|
|
@@ -1,69 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license MIT
|
|
3
|
-
* @copyright
|
|
4
|
-
*
|
|
3
|
+
* @copyright 2030 Tyler Zeng <zrwusa@gmail.com>
|
|
5
4
|
* @class
|
|
6
5
|
*/
|
|
7
6
|
export declare class Stack<T> {
|
|
8
7
|
protected _elements: T[];
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param {
|
|
9
|
+
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
10
|
+
* @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
|
|
11
|
+
* of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
|
|
12
|
+
* is provided and is an array, it is assigned to the `_elements
|
|
12
13
|
*/
|
|
13
14
|
constructor(elements?: T[]);
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
17
|
-
* @returns {
|
|
16
|
+
* The function "fromArray" creates a new Stack object from an array of elements.
|
|
17
|
+
* @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
|
|
18
|
+
* @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
|
|
19
|
+
* array.
|
|
20
|
+
*/
|
|
21
|
+
static fromArray<T>(elements: T[]): Stack<T>;
|
|
22
|
+
/**
|
|
23
|
+
* The function checks if an array is empty and returns a boolean value.
|
|
24
|
+
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
18
25
|
*/
|
|
19
26
|
isEmpty(): boolean;
|
|
20
27
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
23
|
-
* @returns {number}
|
|
28
|
+
* The size() function returns the number of elements in an array.
|
|
29
|
+
* @returns The size of the elements array.
|
|
24
30
|
*/
|
|
25
31
|
size(): number;
|
|
26
32
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
* @returns {object}
|
|
33
|
+
* The `peek` function returns the last element of an array, or null if the array is empty.
|
|
34
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
|
|
30
35
|
*/
|
|
31
36
|
peek(): T | null;
|
|
32
37
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
38
|
+
* The push function adds an element to the stack and returns the updated stack.
|
|
39
|
+
* @param {T} element - The parameter "element" is of type T, which means it can be any data type.
|
|
40
|
+
* @returns The `push` method is returning the updated `Stack<T>` object.
|
|
36
41
|
*/
|
|
37
42
|
push(element: T): Stack<T>;
|
|
38
43
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @
|
|
41
|
-
*
|
|
44
|
+
* The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
|
|
45
|
+
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
46
|
+
* array is empty, it returns `null`.
|
|
42
47
|
*/
|
|
43
48
|
pop(): T | null;
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
* @returns {array}
|
|
50
|
+
* The toArray function returns a copy of the elements in an array.
|
|
51
|
+
* @returns An array of type T.
|
|
48
52
|
*/
|
|
49
53
|
toArray(): T[];
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @public
|
|
55
|
+
* The clear function clears the elements array.
|
|
53
56
|
*/
|
|
54
57
|
clear(): void;
|
|
55
58
|
/**
|
|
56
|
-
*
|
|
57
|
-
* @
|
|
58
|
-
* @return {Stack}
|
|
59
|
+
* The `clone()` function returns a new `Stack` object with the same elements as the original stack.
|
|
60
|
+
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
59
61
|
*/
|
|
60
62
|
clone(): Stack<T>;
|
|
61
|
-
/**
|
|
62
|
-
* Creates a stack from an existing array
|
|
63
|
-
* @public
|
|
64
|
-
* @static
|
|
65
|
-
* @param {array} [elements]
|
|
66
|
-
* @return {Stack}
|
|
67
|
-
*/
|
|
68
|
-
static fromArray<T>(elements: T[]): Stack<T>;
|
|
69
63
|
}
|