data-structure-typed 1.34.8 → 1.35.0
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/.eslintrc.js +1 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/custom.md +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/CHANGELOG.md +1 -1
- package/CONTRIBUTING.md +0 -0
- package/README.md +8 -8
- package/dist/data-structures/binary-tree/aa-tree.js +2 -5
- package/dist/data-structures/binary-tree/aa-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +280 -423
- package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/avl-tree.js +63 -89
- package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/b-tree.js +2 -5
- package/dist/data-structures/binary-tree/b-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
- package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +11 -30
- package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/bst.js +127 -214
- package/dist/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/data-structures/binary-tree/rb-tree.js +19 -43
- package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/segment-tree.js +80 -122
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/splay-tree.js +2 -5
- package/dist/data-structures/binary-tree/splay-tree.js.map +1 -1
- package/dist/data-structures/binary-tree/tree-multiset.js +147 -218
- package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
- package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -1
- package/dist/data-structures/graph/abstract-graph.js +338 -572
- package/dist/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/data-structures/graph/directed-graph.js +145 -275
- package/dist/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/data-structures/graph/map-graph.js +46 -87
- package/dist/data-structures/graph/map-graph.js.map +1 -1
- package/dist/data-structures/graph/undirected-graph.js +90 -179
- package/dist/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/data-structures/hash/coordinate-map.js +23 -45
- package/dist/data-structures/hash/coordinate-map.js.map +1 -1
- package/dist/data-structures/hash/coordinate-set.js +20 -42
- package/dist/data-structures/hash/coordinate-set.js.map +1 -1
- package/dist/data-structures/hash/hash-map.js +85 -247
- package/dist/data-structures/hash/hash-map.js.map +1 -1
- package/dist/data-structures/hash/hash-table.js +87 -128
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/pair.js +2 -5
- package/dist/data-structures/hash/pair.js.map +1 -1
- package/dist/data-structures/hash/tree-map.js +2 -5
- package/dist/data-structures/hash/tree-map.js.map +1 -1
- package/dist/data-structures/hash/tree-set.js +2 -5
- package/dist/data-structures/hash/tree-set.js.map +1 -1
- package/dist/data-structures/heap/heap.js +56 -80
- package/dist/data-structures/heap/heap.js.map +1 -1
- package/dist/data-structures/heap/max-heap.js +8 -26
- package/dist/data-structures/heap/max-heap.js.map +1 -1
- package/dist/data-structures/heap/min-heap.js +8 -26
- package/dist/data-structures/heap/min-heap.js.map +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +149 -218
- package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +119 -218
- package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +50 -70
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/data-structures/matrix/matrix.js +7 -8
- package/dist/data-structures/matrix/matrix.js.map +1 -1
- package/dist/data-structures/matrix/matrix2d.js +57 -70
- package/dist/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/data-structures/matrix/navigator.js +18 -37
- package/dist/data-structures/matrix/navigator.js.map +1 -1
- package/dist/data-structures/matrix/vector2d.js +63 -84
- package/dist/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/data-structures/priority-queue/max-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +13 -41
- package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +93 -139
- package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/data-structures/queue/deque.js +82 -128
- package/dist/data-structures/queue/deque.js.map +1 -1
- package/dist/data-structures/queue/queue.js +57 -157
- package/dist/data-structures/queue/queue.js.map +1 -1
- package/dist/data-structures/stack/stack.js +21 -22
- package/dist/data-structures/stack/stack.js.map +1 -1
- package/dist/data-structures/tree/tree.js +32 -45
- package/dist/data-structures/tree/tree.js.map +1 -1
- package/dist/data-structures/trie/trie.js +93 -200
- package/dist/data-structures/trie/trie.js.map +1 -1
- package/dist/types/data-structures/abstract-binary-tree.js.map +1 -1
- package/dist/utils/utils.js +22 -107
- package/dist/utils/utils.js.map +1 -1
- package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +79 -78
- package/lib/data-structures/binary-tree/abstract-binary-tree.js +61 -141
- package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -0
- package/lib/data-structures/binary-tree/avl-tree.js +22 -0
- package/lib/data-structures/binary-tree/bst.d.ts +3 -3
- package/lib/data-structures/binary-tree/bst.js +12 -15
- package/lib/data-structures/binary-tree/tree-multiset.d.ts +16 -18
- package/lib/data-structures/binary-tree/tree-multiset.js +26 -36
- package/lib/data-structures/graph/abstract-graph.d.ts +2 -2
- package/lib/data-structures/graph/abstract-graph.js +5 -5
- package/lib/data-structures/priority-queue/priority-queue.d.ts +3 -3
- package/lib/data-structures/priority-queue/priority-queue.js +3 -3
- package/lib/interfaces/abstract-binary-tree.d.ts +1 -83
- package/lib/interfaces/abstract-graph.d.ts +2 -14
- package/lib/interfaces/avl-tree.d.ts +3 -4
- package/lib/interfaces/binary-tree.d.ts +4 -2
- package/lib/interfaces/bst.d.ts +2 -12
- package/lib/interfaces/directed-graph.d.ts +0 -9
- package/lib/interfaces/rb-tree.d.ts +2 -3
- package/lib/interfaces/tree-multiset.d.ts +5 -4
- package/lib/interfaces/undirected-graph.d.ts +0 -2
- package/lib/types/data-structures/abstract-binary-tree.js +0 -1
- package/package.json +7 -7
- package/src/data-structures/binary-tree/abstract-binary-tree.ts +151 -203
- package/src/data-structures/binary-tree/avl-tree.ts +29 -0
- package/src/data-structures/binary-tree/bst.ts +12 -15
- package/src/data-structures/binary-tree/tree-multiset.ts +27 -39
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/interfaces/abstract-binary-tree.ts +2 -183
- package/src/interfaces/abstract-graph.ts +2 -26
- package/src/interfaces/avl-tree.ts +4 -21
- package/src/interfaces/binary-tree.ts +3 -2
- package/src/interfaces/bst.ts +2 -27
- package/src/interfaces/directed-graph.ts +1 -18
- package/src/interfaces/rb-tree.ts +2 -5
- package/src/interfaces/tree-multiset.ts +4 -4
- package/src/interfaces/undirected-graph.ts +1 -4
- package/src/types/data-structures/abstract-binary-tree.ts +0 -1
- package/test/integration/avl-tree.test.ts +24 -24
- package/test/integration/bst.test.ts +71 -71
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -9
- package/test/unit/data-structures/binary-tree/bst.test.ts +8 -8
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +9 -9
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
|
@@ -1,191 +1,91 @@
|
|
|
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
|
-
})();
|
|
17
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
18
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
19
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
20
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
21
|
-
function step(op) {
|
|
22
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
23
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
24
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
25
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
26
|
-
switch (op[0]) {
|
|
27
|
-
case 0: case 1: t = op; break;
|
|
28
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
29
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
30
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
31
|
-
default:
|
|
32
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
33
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
34
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
35
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
36
|
-
if (t[2]) _.ops.pop();
|
|
37
|
-
_.trys.pop(); continue;
|
|
38
|
-
}
|
|
39
|
-
op = body.call(thisArg, _);
|
|
40
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
41
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var __values = (this && this.__values) || function(o) {
|
|
45
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
46
|
-
if (m) return m.call(o);
|
|
47
|
-
if (o && typeof o.length === "number") return {
|
|
48
|
-
next: function () {
|
|
49
|
-
if (o && i >= o.length) o = void 0;
|
|
50
|
-
return { value: o && o[i++], done: !o };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
54
|
-
};
|
|
55
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
3
|
exports.Queue = exports.LinkedListQueue = void 0;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
function LinkedListQueue() {
|
|
61
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
62
|
-
}
|
|
63
|
-
LinkedListQueue.prototype.enqueue = function (value) {
|
|
4
|
+
const linked_list_1 = require("../linked-list");
|
|
5
|
+
class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
6
|
+
enqueue(value) {
|
|
64
7
|
this.push(value);
|
|
65
|
-
}
|
|
66
|
-
|
|
8
|
+
}
|
|
9
|
+
dequeue() {
|
|
67
10
|
return this.shift();
|
|
68
|
-
}
|
|
69
|
-
|
|
11
|
+
}
|
|
12
|
+
peek() {
|
|
70
13
|
var _a;
|
|
71
14
|
return (_a = this.head) === null || _a === void 0 ? void 0 : _a.val;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}(linked_list_1.SinglyLinkedList));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
75
17
|
exports.LinkedListQueue = LinkedListQueue;
|
|
76
|
-
|
|
77
|
-
|
|
18
|
+
class Queue {
|
|
19
|
+
constructor(elements) {
|
|
78
20
|
this._nodes = elements || [];
|
|
79
21
|
this._offset = 0;
|
|
80
22
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
enumerable: false,
|
|
99
|
-
configurable: true
|
|
100
|
-
});
|
|
101
|
-
Object.defineProperty(Queue.prototype, "size", {
|
|
102
|
-
get: function () {
|
|
103
|
-
return this.nodes.length - this.offset;
|
|
104
|
-
},
|
|
105
|
-
enumerable: false,
|
|
106
|
-
configurable: true
|
|
107
|
-
});
|
|
108
|
-
Queue.fromArray = function (elements) {
|
|
23
|
+
get nodes() {
|
|
24
|
+
return this._nodes;
|
|
25
|
+
}
|
|
26
|
+
set nodes(value) {
|
|
27
|
+
this._nodes = value;
|
|
28
|
+
}
|
|
29
|
+
get offset() {
|
|
30
|
+
return this._offset;
|
|
31
|
+
}
|
|
32
|
+
set offset(value) {
|
|
33
|
+
this._offset = value;
|
|
34
|
+
}
|
|
35
|
+
get size() {
|
|
36
|
+
return this.nodes.length - this.offset;
|
|
37
|
+
}
|
|
38
|
+
static fromArray(elements) {
|
|
109
39
|
return new Queue(elements);
|
|
110
|
-
}
|
|
111
|
-
|
|
40
|
+
}
|
|
41
|
+
push(element) {
|
|
112
42
|
this.nodes.push(element);
|
|
113
43
|
return this;
|
|
114
|
-
}
|
|
115
|
-
|
|
44
|
+
}
|
|
45
|
+
shift() {
|
|
116
46
|
if (this.size === 0)
|
|
117
47
|
return undefined;
|
|
118
|
-
|
|
48
|
+
const first = this.peek();
|
|
119
49
|
this.offset += 1;
|
|
120
50
|
if (this.offset * 2 < this.nodes.length)
|
|
121
51
|
return first;
|
|
122
52
|
this.nodes = this.nodes.slice(this.offset);
|
|
123
53
|
this.offset = 0;
|
|
124
54
|
return first;
|
|
125
|
-
}
|
|
126
|
-
|
|
55
|
+
}
|
|
56
|
+
peek() {
|
|
127
57
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
128
|
-
}
|
|
129
|
-
|
|
58
|
+
}
|
|
59
|
+
peekLast() {
|
|
130
60
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
131
|
-
}
|
|
132
|
-
|
|
61
|
+
}
|
|
62
|
+
enqueue(value) {
|
|
133
63
|
this.push(value);
|
|
134
|
-
}
|
|
135
|
-
|
|
64
|
+
}
|
|
65
|
+
dequeue() {
|
|
136
66
|
return this.shift();
|
|
137
|
-
}
|
|
138
|
-
|
|
67
|
+
}
|
|
68
|
+
getAt(index) {
|
|
139
69
|
return this.nodes[index];
|
|
140
|
-
}
|
|
141
|
-
|
|
70
|
+
}
|
|
71
|
+
isEmpty() {
|
|
142
72
|
return this.size === 0;
|
|
143
|
-
}
|
|
144
|
-
|
|
73
|
+
}
|
|
74
|
+
toArray() {
|
|
145
75
|
return this.nodes.slice(this.offset);
|
|
146
|
-
}
|
|
147
|
-
|
|
76
|
+
}
|
|
77
|
+
clear() {
|
|
148
78
|
this.nodes = [];
|
|
149
79
|
this.offset = 0;
|
|
150
|
-
}
|
|
151
|
-
|
|
80
|
+
}
|
|
81
|
+
clone() {
|
|
152
82
|
return new Queue(this.nodes.slice(this.offset));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
_d.trys.push([0, 5, 6, 7]);
|
|
161
|
-
_a = __values(this.nodes), _b = _a.next();
|
|
162
|
-
_d.label = 1;
|
|
163
|
-
case 1:
|
|
164
|
-
if (!!_b.done) return [3, 4];
|
|
165
|
-
item = _b.value;
|
|
166
|
-
return [4, item];
|
|
167
|
-
case 2:
|
|
168
|
-
_d.sent();
|
|
169
|
-
_d.label = 3;
|
|
170
|
-
case 3:
|
|
171
|
-
_b = _a.next();
|
|
172
|
-
return [3, 1];
|
|
173
|
-
case 4: return [3, 7];
|
|
174
|
-
case 5:
|
|
175
|
-
e_1_1 = _d.sent();
|
|
176
|
-
e_1 = { error: e_1_1 };
|
|
177
|
-
return [3, 7];
|
|
178
|
-
case 6:
|
|
179
|
-
try {
|
|
180
|
-
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
181
|
-
}
|
|
182
|
-
finally { if (e_1) throw e_1.error; }
|
|
183
|
-
return [7];
|
|
184
|
-
case 7: return [2];
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
return Queue;
|
|
189
|
-
}());
|
|
83
|
+
}
|
|
84
|
+
*[Symbol.iterator]() {
|
|
85
|
+
for (const item of this.nodes) {
|
|
86
|
+
yield item;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
190
90
|
exports.Queue = Queue;
|
|
191
91
|
//# sourceMappingURL=queue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"queue.js","sourceR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K,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE;YAC7B,MAAM,IAAI,CAAC;SACZ;IACH,CAAC;CACF;AA7JD,sBA6JC"}
|
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Stack = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Stack {
|
|
5
|
+
constructor(elements) {
|
|
6
6
|
this._elements = Array.isArray(elements) ? elements : [];
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
static fromArray(elements) {
|
|
9
9
|
return new Stack(elements);
|
|
10
|
-
}
|
|
11
|
-
|
|
10
|
+
}
|
|
11
|
+
isEmpty() {
|
|
12
12
|
return this._elements.length === 0;
|
|
13
|
-
}
|
|
14
|
-
|
|
13
|
+
}
|
|
14
|
+
size() {
|
|
15
15
|
return this._elements.length;
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
}
|
|
17
|
+
peek() {
|
|
18
18
|
if (this.isEmpty())
|
|
19
19
|
return null;
|
|
20
20
|
return this._elements[this._elements.length - 1];
|
|
21
|
-
}
|
|
22
|
-
|
|
21
|
+
}
|
|
22
|
+
push(element) {
|
|
23
23
|
this._elements.push(element);
|
|
24
24
|
return this;
|
|
25
|
-
}
|
|
26
|
-
|
|
25
|
+
}
|
|
26
|
+
pop() {
|
|
27
27
|
if (this.isEmpty())
|
|
28
28
|
return null;
|
|
29
29
|
return this._elements.pop() || null;
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
}
|
|
31
|
+
toArray() {
|
|
32
32
|
return this._elements.slice();
|
|
33
|
-
}
|
|
34
|
-
|
|
33
|
+
}
|
|
34
|
+
clear() {
|
|
35
35
|
this._elements = [];
|
|
36
|
-
}
|
|
37
|
-
|
|
36
|
+
}
|
|
37
|
+
clone() {
|
|
38
38
|
return new Stack(this._elements.slice());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
42
41
|
exports.Stack = Stack;
|
|
43
42
|
//# sourceMappingURL=stack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAKA;
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAKA,MAAa,KAAK;IAShB,YAAY,QAAc;QACxB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3D,CAAC;IAQD,MAAM,CAAC,SAAS,CAAI,QAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAMD,OAAO;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IACrC,CAAC;IAMD,IAAI;QACF,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAMD,IAAI;QACF,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAC;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAOD,IAAI,CAAC,OAAU;QACb,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAOD,GAAG;QACD,IAAI,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO,IAAI,CAAC;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC;IACtC,CAAC;IAMD,OAAO;QACL,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAKD,KAAK;QACH,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAMD,KAAK;QACH,OAAO,IAAI,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AA5FD,sBA4FC"}
|
|
@@ -1,43 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TreeNode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class TreeNode {
|
|
5
|
+
constructor(key, value, children) {
|
|
6
6
|
this._key = key;
|
|
7
7
|
this._value = value || undefined;
|
|
8
8
|
this._children = children || [];
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(TreeNode.prototype, "children", {
|
|
31
|
-
get: function () {
|
|
32
|
-
return this._children;
|
|
33
|
-
},
|
|
34
|
-
set: function (value) {
|
|
35
|
-
this._children = value;
|
|
36
|
-
},
|
|
37
|
-
enumerable: false,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
|
-
TreeNode.prototype.addChildren = function (children) {
|
|
10
|
+
get key() {
|
|
11
|
+
return this._key;
|
|
12
|
+
}
|
|
13
|
+
set key(value) {
|
|
14
|
+
this._key = value;
|
|
15
|
+
}
|
|
16
|
+
get value() {
|
|
17
|
+
return this._value;
|
|
18
|
+
}
|
|
19
|
+
set value(value) {
|
|
20
|
+
this._value = value;
|
|
21
|
+
}
|
|
22
|
+
get children() {
|
|
23
|
+
return this._children;
|
|
24
|
+
}
|
|
25
|
+
set children(value) {
|
|
26
|
+
this._children = value;
|
|
27
|
+
}
|
|
28
|
+
addChildren(children) {
|
|
41
29
|
if (!this.children) {
|
|
42
30
|
this.children = [];
|
|
43
31
|
}
|
|
@@ -47,27 +35,26 @@ var TreeNode = (function () {
|
|
|
47
35
|
else {
|
|
48
36
|
this.children = this.children.concat(children);
|
|
49
37
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
}
|
|
39
|
+
getHeight() {
|
|
40
|
+
const beginRoot = this;
|
|
41
|
+
let maxDepth = 1;
|
|
54
42
|
if (beginRoot) {
|
|
55
|
-
|
|
43
|
+
const bfs = (node, level) => {
|
|
56
44
|
if (level > maxDepth) {
|
|
57
45
|
maxDepth = level;
|
|
58
46
|
}
|
|
59
|
-
|
|
47
|
+
const { children } = node;
|
|
60
48
|
if (children) {
|
|
61
|
-
for (
|
|
62
|
-
|
|
49
|
+
for (let i = 0, len = children.length; i < len; i++) {
|
|
50
|
+
bfs(children[i], level + 1);
|
|
63
51
|
}
|
|
64
52
|
}
|
|
65
53
|
};
|
|
66
|
-
|
|
54
|
+
bfs(beginRoot, 1);
|
|
67
55
|
}
|
|
68
56
|
return maxDepth;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
72
59
|
exports.TreeNode = TreeNode;
|
|
73
60
|
//# sourceMappingURL=tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/data-structures/tree/tree.ts"],"names":[],"mappings":";;;AAAA;
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/data-structures/tree/tree.ts"],"names":[],"mappings":";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