@raikuxq/alg-ds 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/lib/algorithms/binary-search.d.ts +5 -0
  2. package/lib/algorithms/binary-search.js +27 -0
  3. package/lib/algorithms/factorial.d.ts +9 -0
  4. package/lib/algorithms/factorial.js +17 -0
  5. package/lib/algorithms/fibonacci.d.ts +9 -0
  6. package/lib/algorithms/fibonacci.js +17 -0
  7. package/lib/algorithms/memoize.d.ts +5 -0
  8. package/lib/algorithms/memoize.js +22 -0
  9. package/lib/algorithms/sorts/bubble-sort.d.ts +9 -0
  10. package/lib/algorithms/sorts/bubble-sort.js +23 -0
  11. package/lib/algorithms/sorts/insertion-sort.d.ts +9 -0
  12. package/lib/algorithms/sorts/insertion-sort.js +25 -0
  13. package/lib/algorithms/sorts/merge-sort.d.ts +9 -0
  14. package/lib/algorithms/sorts/merge-sort.js +61 -0
  15. package/lib/algorithms/sorts/quick-sort.d.ts +9 -0
  16. package/lib/algorithms/sorts/quick-sort.js +45 -0
  17. package/lib/algorithms/sorts/select-sort.d.ts +9 -0
  18. package/lib/algorithms/sorts/select-sort.js +20 -0
  19. package/lib/algorithms/transpose-matrix.d.ts +5 -0
  20. package/lib/algorithms/transpose-matrix.js +18 -0
  21. package/lib/constants.d.ts +2 -0
  22. package/lib/constants.js +6 -0
  23. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.d.ts +15 -0
  24. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryNode.js +53 -0
  25. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.d.ts +60 -0
  26. package/lib/data-structures/BinaryTree/AbstractBinaryTree/AbstractBinaryTree.js +36 -0
  27. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.d.ts +13 -0
  28. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchNode.js +59 -0
  29. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.d.ts +70 -0
  30. package/lib/data-structures/BinaryTree/BinarySearchTree/BinarySearchTree.js +271 -0
  31. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.d.ts +16 -0
  32. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchNode.js +70 -0
  33. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.d.ts +57 -0
  34. package/lib/data-structures/BinaryTree/RandBinarySearchTree/RandBinarySearchTree.js +235 -0
  35. package/lib/data-structures/Graph/AbstractGraph.d.ts +84 -0
  36. package/lib/data-structures/Graph/AbstractGraph.js +143 -0
  37. package/lib/data-structures/Graph/DirectedGraph.d.ts +24 -0
  38. package/lib/data-structures/Graph/DirectedGraph.js +86 -0
  39. package/lib/data-structures/Graph/GraphEdge.d.ts +16 -0
  40. package/lib/data-structures/Graph/GraphEdge.js +43 -0
  41. package/lib/data-structures/Graph/UndirectedGraph.d.ts +28 -0
  42. package/lib/data-structures/Graph/UndirectedGraph.js +103 -0
  43. package/lib/data-structures/Graph/demo/generateRandomGraph.d.ts +4 -0
  44. package/lib/data-structures/Graph/demo/generateRandomGraph.js +66 -0
  45. package/lib/data-structures/Graph/iterator/AbstractGraphIterator.d.ts +35 -0
  46. package/lib/data-structures/Graph/iterator/AbstractGraphIterator.js +90 -0
  47. package/lib/data-structures/Graph/iterator/GraphIteratorBFS.d.ts +28 -0
  48. package/lib/data-structures/Graph/iterator/GraphIteratorBFS.js +70 -0
  49. package/lib/data-structures/Graph/iterator/GraphIteratorDFS.d.ts +28 -0
  50. package/lib/data-structures/Graph/iterator/GraphIteratorDFS.js +70 -0
  51. package/lib/data-structures/Graph/iterator/GraphIteratorDijkstra.d.ts +32 -0
  52. package/lib/data-structures/Graph/iterator/GraphIteratorDijkstra.js +99 -0
  53. package/lib/data-structures/Graph/presenter/presenterAdjacencyLists.d.ts +19 -0
  54. package/lib/data-structures/Graph/presenter/presenterAdjacencyLists.js +28 -0
  55. package/lib/data-structures/Graph/presenter/presenterAdjacencyMatrix.d.ts +32 -0
  56. package/lib/data-structures/Graph/presenter/presenterAdjacencyMatrix.js +48 -0
  57. package/lib/data-structures/Graph/searching/hasPath.d.ts +9 -0
  58. package/lib/data-structures/Graph/searching/hasPath.js +30 -0
  59. package/lib/data-structures/Graph/searching/shortestPath.d.ts +9 -0
  60. package/lib/data-structures/Graph/searching/shortestPath.js +30 -0
  61. package/lib/data-structures/Graph/strategy/BFSIterationStrategy.d.ts +6 -0
  62. package/lib/data-structures/Graph/strategy/BFSIterationStrategy.js +13 -0
  63. package/lib/data-structures/Graph/strategy/DFSIterationStrategy.d.ts +6 -0
  64. package/lib/data-structures/Graph/strategy/DFSIterationStrategy.js +13 -0
  65. package/lib/data-structures/Graph/strategy/DijkstraIterationStrategy.d.ts +6 -0
  66. package/lib/data-structures/Graph/strategy/DijkstraIterationStrategy.js +13 -0
  67. package/lib/data-structures/Graph/transposing/transposeDirectedGraph.d.ts +2 -0
  68. package/lib/data-structures/Graph/transposing/transposeDirectedGraph.js +14 -0
  69. package/lib/data-structures/HashTable/HashTable.d.ts +73 -0
  70. package/lib/data-structures/HashTable/HashTable.js +171 -0
  71. package/lib/data-structures/HashTable/HashTableNode.d.ts +11 -0
  72. package/lib/data-structures/HashTable/HashTableNode.js +39 -0
  73. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.d.ts +125 -0
  74. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedList.js +241 -0
  75. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.d.ts +20 -0
  76. package/lib/data-structures/LinkedList/AbstractLinkedList/AbstractLinkedNode.js +41 -0
  77. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.d.ts +48 -0
  78. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedList.js +151 -0
  79. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.d.ts +25 -0
  80. package/lib/data-structures/LinkedList/DoubleLinkedList/DoubleLinkedNode.js +65 -0
  81. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.d.ts +52 -0
  82. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedList.js +138 -0
  83. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.d.ts +7 -0
  84. package/lib/data-structures/LinkedList/SingleLinkedList/SingleLinkedNode.js +29 -0
  85. package/lib/data-structures/LoopedArray/LoopedArray.d.ts +83 -0
  86. package/lib/data-structures/LoopedArray/LoopedArray.js +169 -0
  87. package/lib/data-structures/Queue/Queue.d.ts +50 -0
  88. package/lib/data-structures/Queue/Queue.js +85 -0
  89. package/lib/data-structures/Stack/Stack.d.ts +50 -0
  90. package/lib/data-structures/Stack/Stack.js +85 -0
  91. package/lib/exceptions/IllegalCapacityException.d.ts +4 -0
  92. package/lib/exceptions/IllegalCapacityException.js +28 -0
  93. package/lib/exceptions/IndexOutOfBoundsException.d.ts +4 -0
  94. package/lib/exceptions/IndexOutOfBoundsException.js +28 -0
  95. package/lib/exceptions/IsAlreadyExistsException.d.ts +4 -0
  96. package/lib/exceptions/IsAlreadyExistsException.js +28 -0
  97. package/lib/exceptions/IsEmptyException.d.ts +4 -0
  98. package/lib/exceptions/IsEmptyException.js +28 -0
  99. package/lib/exceptions/IsFullException.d.ts +4 -0
  100. package/lib/exceptions/IsFullException.js +28 -0
  101. package/lib/exceptions/IsNotFoundException.d.ts +4 -0
  102. package/lib/exceptions/IsNotFoundException.js +28 -0
  103. package/lib/exceptions/base/IllegalArgumentException.d.ts +3 -0
  104. package/lib/exceptions/base/IllegalArgumentException.js +27 -0
  105. package/lib/exceptions/base/IllegalStateException.d.ts +3 -0
  106. package/lib/exceptions/base/IllegalStateException.js +27 -0
  107. package/lib/exports/algorithms.d.ts +16 -0
  108. package/lib/exports/algorithms.js +36 -0
  109. package/lib/exports/constants.d.ts +2 -0
  110. package/lib/exports/constants.js +7 -0
  111. package/lib/exports/data-structures.d.ts +11 -0
  112. package/lib/exports/data-structures.js +24 -0
  113. package/lib/exports/helpers.d.ts +6 -0
  114. package/lib/exports/helpers.js +14 -0
  115. package/lib/exports/sorts.d.ts +6 -0
  116. package/lib/exports/sorts.js +14 -0
  117. package/lib/exports/utils.d.ts +3 -0
  118. package/lib/exports/utils.js +14 -0
  119. package/lib/exports.d.ts +52 -0
  120. package/lib/exports.js +103 -0
  121. package/lib/helpers/createBinaryTree.d.ts +6 -0
  122. package/lib/helpers/createBinaryTree.js +22 -0
  123. package/lib/helpers/createGraph.d.ts +6 -0
  124. package/lib/helpers/createGraph.js +24 -0
  125. package/lib/helpers/createGraphFromMatrix.d.ts +7 -0
  126. package/lib/helpers/createGraphFromMatrix.js +42 -0
  127. package/lib/helpers/createLinkedList.d.ts +3 -0
  128. package/lib/helpers/createLinkedList.js +21 -0
  129. package/lib/index.d.ts +3 -0
  130. package/lib/index.js +6 -0
  131. package/lib/types/ArrayMatrix.d.ts +1 -0
  132. package/lib/types/ArrayMatrix.js +3 -0
  133. package/lib/types/EnumBinarySearchTreeType.d.ts +4 -0
  134. package/lib/types/EnumBinarySearchTreeType.js +9 -0
  135. package/lib/types/EnumGraphType.d.ts +4 -0
  136. package/lib/types/EnumGraphType.js +9 -0
  137. package/lib/types/EnumLinkedListType.d.ts +4 -0
  138. package/lib/types/EnumLinkedListType.js +9 -0
  139. package/lib/types/EnumRandomGenerationFormat.d.ts +4 -0
  140. package/lib/types/EnumRandomGenerationFormat.js +9 -0
  141. package/lib/types/EnumTreeTraversalType.d.ts +5 -0
  142. package/lib/types/EnumTreeTraversalType.js +10 -0
  143. package/lib/types/FnCompareTwo.d.ts +1 -0
  144. package/lib/types/FnCompareTwo.js +3 -0
  145. package/lib/types/FnToMemoize.d.ts +1 -0
  146. package/lib/types/FnToMemoize.js +3 -0
  147. package/lib/types/IArrayFacade.d.ts +4 -0
  148. package/lib/types/IArrayFacade.js +3 -0
  149. package/lib/types/IBiDirectIterable.d.ts +5 -0
  150. package/lib/types/IBiDirectIterable.js +3 -0
  151. package/lib/types/IBiDirectIterator.d.ts +11 -0
  152. package/lib/types/IBiDirectIterator.js +3 -0
  153. package/lib/types/IBinaryTree.d.ts +12 -0
  154. package/lib/types/IBinaryTree.js +3 -0
  155. package/lib/types/IConvertableToArray.d.ts +4 -0
  156. package/lib/types/IConvertableToArray.js +3 -0
  157. package/lib/types/IGraph.d.ts +14 -0
  158. package/lib/types/IGraph.js +3 -0
  159. package/lib/types/IGraphIterationStrategy.d.ts +5 -0
  160. package/lib/types/IGraphIterationStrategy.js +3 -0
  161. package/lib/types/IGraphIterator.d.ts +11 -0
  162. package/lib/types/IGraphIterator.js +3 -0
  163. package/lib/types/IIterable.d.ts +4 -0
  164. package/lib/types/IIterable.js +3 -0
  165. package/lib/types/IIterator.d.ts +14 -0
  166. package/lib/types/IIterator.js +3 -0
  167. package/lib/types/IKeyValueStorage.d.ts +8 -0
  168. package/lib/types/IKeyValueStorage.js +3 -0
  169. package/lib/types/ILinearStorage.d.ts +11 -0
  170. package/lib/types/ILinearStorage.js +3 -0
  171. package/lib/types/ILinearStorageRA.d.ts +13 -0
  172. package/lib/types/ILinearStorageRA.js +3 -0
  173. package/lib/types/ILinkedList.d.ts +4 -0
  174. package/lib/types/ILinkedList.js +3 -0
  175. package/lib/utils.d.ts +33 -0
  176. package/lib/utils.js +108 -0
  177. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ import { FnCompareTwo } from "../../../types/FnCompareTwo";
2
+ import { EnumTreeTraversalType } from "../../../types/EnumTreeTraversalType";
3
+ import IBinaryTree from "../../../types/IBinaryTree";
4
+ import AbstractBinaryTree from "../AbstractBinaryTree/AbstractBinaryTree";
5
+ import BinarySearchNode from "./BinarySearchNode";
6
+ /**
7
+ * Unbalanced binary search tree implementation
8
+ */
9
+ export default class BinarySearchTree<T> extends AbstractBinaryTree<T> {
10
+ /**
11
+ * Override types
12
+ */
13
+ protected _head: BinarySearchNode<T> | null;
14
+ /**
15
+ * @inheritDoc
16
+ */
17
+ constructor(fnCompare?: FnCompareTwo<T>);
18
+ /**
19
+ *
20
+ * @throws when head is empty
21
+ */
22
+ protected checkIsEmpty(): void;
23
+ /**
24
+ * Will update left and right links parent with current node
25
+ */
26
+ protected updateLeftRightParents(node: BinarySearchNode<T>): void;
27
+ /**
28
+ * Will return node instance by its data
29
+ */
30
+ protected findNode(value: T): BinarySearchNode<T> | null;
31
+ /**
32
+ * @inheritDoc
33
+ */
34
+ protected insertToLeaf(createdNode: BinarySearchNode<T>): void;
35
+ /**
36
+ * Will join two trees into one */
37
+ protected join(treeLeft: BinarySearchNode<T> | null, treeRight: BinarySearchNode<T> | null): BinarySearchNode<T> | null;
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ max(): T;
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ min(): T;
46
+ /**
47
+ * @inheritDoc
48
+ */
49
+ insert(value: T): void;
50
+ /**
51
+ * @inheritDoc
52
+ */
53
+ has(value: T): boolean;
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ delete(value: T): void;
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ subtree(value: T): IBinaryTree<T>;
62
+ /**
63
+ * @inheritDoc
64
+ */
65
+ traverse(type: EnumTreeTraversalType, from?: T): Array<T>;
66
+ /**
67
+ * Calc max height of the largest branch of the tree
68
+ */
69
+ height(): number;
70
+ }
@@ -0,0 +1,271 @@
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
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var EnumTreeTraversalType_1 = require("../../../types/EnumTreeTraversalType");
17
+ var AbstractBinaryTree_1 = require("../AbstractBinaryTree/AbstractBinaryTree");
18
+ var BinarySearchNode_1 = require("./BinarySearchNode");
19
+ var Queue_1 = require("../../Queue/Queue");
20
+ var IsAlreadyExistsException_1 = require("../../../exceptions/IsAlreadyExistsException");
21
+ var IsNotFoundException_1 = require("../../../exceptions/IsNotFoundException");
22
+ var IsEmptyException_1 = require("../../../exceptions/IsEmptyException");
23
+ /**
24
+ * Unbalanced binary search tree implementation
25
+ */
26
+ var BinarySearchTree = /** @class */ (function (_super) {
27
+ __extends(BinarySearchTree, _super);
28
+ /**
29
+ * @inheritDoc
30
+ */
31
+ function BinarySearchTree(fnCompare) {
32
+ var _this = _super.call(this, fnCompare) || this;
33
+ _this._head = null;
34
+ return _this;
35
+ }
36
+ /**
37
+ *
38
+ * @throws when head is empty
39
+ */
40
+ BinarySearchTree.prototype.checkIsEmpty = function () {
41
+ if (this._head === null) {
42
+ throw new IsEmptyException_1.default("Tree is empty");
43
+ }
44
+ };
45
+ /**
46
+ * Will update left and right links parent with current node
47
+ */
48
+ BinarySearchTree.prototype.updateLeftRightParents = function (node) {
49
+ if (node.left && node.left.parent !== node) {
50
+ node.left.parent = node;
51
+ }
52
+ if (node.right && node.right.parent !== node) {
53
+ node.right.parent = node;
54
+ }
55
+ };
56
+ /**
57
+ * Will return node instance by its data
58
+ */
59
+ BinarySearchTree.prototype.findNode = function (value) {
60
+ var current = this._head;
61
+ while (current && current.data !== value) {
62
+ current = this.compare(current.data, value)
63
+ ? current.left
64
+ : current.right;
65
+ }
66
+ return current;
67
+ };
68
+ /**
69
+ * @inheritDoc
70
+ */
71
+ BinarySearchTree.prototype.insertToLeaf = function (createdNode) {
72
+ var parent = null;
73
+ var current = this._head;
74
+ while (current) {
75
+ parent = current;
76
+ current = this.compare(current.data, createdNode.data)
77
+ ? current.left
78
+ : current.right;
79
+ }
80
+ createdNode.parent = parent;
81
+ if (parent === null) {
82
+ this._head = createdNode;
83
+ }
84
+ else {
85
+ if (this.compare(parent.data, createdNode.data)) {
86
+ parent.left = createdNode;
87
+ }
88
+ else {
89
+ parent.right = createdNode;
90
+ }
91
+ }
92
+ this._length++;
93
+ };
94
+ /**
95
+ * Will join two trees into one */
96
+ BinarySearchTree.prototype.join = function (treeLeft, treeRight) {
97
+ if (treeLeft === null) {
98
+ return treeRight;
99
+ }
100
+ if (treeRight === null) {
101
+ return treeLeft;
102
+ }
103
+ treeRight.left = this.join(treeLeft, treeRight.left);
104
+ if (treeRight.left) {
105
+ this.updateLeftRightParents(treeRight);
106
+ }
107
+ return treeRight;
108
+ };
109
+ /**
110
+ * @inheritDoc
111
+ */
112
+ BinarySearchTree.prototype.max = function () {
113
+ this.checkIsEmpty();
114
+ var currentNode = this._head;
115
+ while (currentNode === null || currentNode === void 0 ? void 0 : currentNode.right) {
116
+ currentNode = currentNode.right;
117
+ }
118
+ return currentNode.data;
119
+ };
120
+ /**
121
+ * @inheritDoc
122
+ */
123
+ BinarySearchTree.prototype.min = function () {
124
+ this.checkIsEmpty();
125
+ var currentNode = this._head;
126
+ while (currentNode === null || currentNode === void 0 ? void 0 : currentNode.left) {
127
+ currentNode = currentNode.left;
128
+ }
129
+ return currentNode.data;
130
+ };
131
+ /**
132
+ * @inheritDoc
133
+ */
134
+ BinarySearchTree.prototype.insert = function (value) {
135
+ if (this.has(value)) {
136
+ throw new IsAlreadyExistsException_1.default("Node already exists");
137
+ }
138
+ var createdNode = new BinarySearchNode_1.default(value);
139
+ this.insertToLeaf(createdNode);
140
+ };
141
+ /**
142
+ * @inheritDoc
143
+ */
144
+ BinarySearchTree.prototype.has = function (value) {
145
+ var current = this.findNode(value);
146
+ return (current === null || current === void 0 ? void 0 : current.data) === value;
147
+ };
148
+ /**
149
+ * @inheritDoc
150
+ */
151
+ BinarySearchTree.prototype.delete = function (value) {
152
+ var _this = this;
153
+ if (!this.has(value)) {
154
+ throw new IsNotFoundException_1.default("Value does not exist in the tree");
155
+ }
156
+ var recursiveDelete = function (node, value) {
157
+ if (node === null) {
158
+ return node;
159
+ }
160
+ if (node.data === value) {
161
+ var updatedNode = _this.join(node.left, node.right);
162
+ if (updatedNode) {
163
+ updatedNode.parent = node.parent;
164
+ }
165
+ return updatedNode;
166
+ }
167
+ else if (_this.compare(node.data, value)) {
168
+ node.left = recursiveDelete(node.left, value);
169
+ }
170
+ else {
171
+ node.right = recursiveDelete(node.right, value);
172
+ }
173
+ _this.updateLeftRightParents(node);
174
+ return node;
175
+ };
176
+ this._head = recursiveDelete(this._head, value);
177
+ this._length--;
178
+ };
179
+ /**
180
+ * @inheritDoc
181
+ */
182
+ BinarySearchTree.prototype.subtree = function (value) {
183
+ var tree = new BinarySearchTree();
184
+ var node = this.findNode(value);
185
+ var queue = new Queue_1.default();
186
+ var traverse = [];
187
+ queue.push(node);
188
+ while (!queue.isEmpty()) {
189
+ var currentNode = queue.pop();
190
+ traverse.push(currentNode);
191
+ if (currentNode === null || currentNode === void 0 ? void 0 : currentNode.left) {
192
+ queue.push(currentNode.left);
193
+ }
194
+ if (currentNode === null || currentNode === void 0 ? void 0 : currentNode.right) {
195
+ queue.push(currentNode.right);
196
+ }
197
+ }
198
+ traverse.forEach(function (elem) {
199
+ if (elem !== null) {
200
+ tree.insert(elem.data);
201
+ }
202
+ });
203
+ return tree;
204
+ };
205
+ /**
206
+ * @inheritDoc
207
+ */
208
+ BinarySearchTree.prototype.traverse = function (type, from) {
209
+ this.checkIsEmpty();
210
+ var array = new Array(this.length());
211
+ var root = from !== undefined ? this.findNode(from) : this._head;
212
+ var storeInOrder = function (node) {
213
+ if (node === null) {
214
+ return;
215
+ }
216
+ storeInOrder(node.left);
217
+ array.push(node.data);
218
+ storeInOrder(node.right);
219
+ };
220
+ var storePostOrder = function (node) {
221
+ if (node === null) {
222
+ return;
223
+ }
224
+ storeInOrder(node.left);
225
+ storeInOrder(node.right);
226
+ array.push(node.data);
227
+ };
228
+ var storePreOrder = function (node) {
229
+ if (node === null) {
230
+ return;
231
+ }
232
+ array.push(node.data);
233
+ storeInOrder(node.left);
234
+ storeInOrder(node.right);
235
+ };
236
+ switch (type) {
237
+ case EnumTreeTraversalType_1.EnumTreeTraversalType.InOrder:
238
+ storeInOrder(root);
239
+ break;
240
+ case EnumTreeTraversalType_1.EnumTreeTraversalType.PostOrder:
241
+ storePostOrder(root);
242
+ break;
243
+ case EnumTreeTraversalType_1.EnumTreeTraversalType.PreOrder:
244
+ storePreOrder(root);
245
+ break;
246
+ }
247
+ return array.filter(function (item) { return item !== undefined; });
248
+ };
249
+ /**
250
+ * Calc max height of the largest branch of the tree
251
+ */
252
+ BinarySearchTree.prototype.height = function () {
253
+ var calcHeight = function (node) {
254
+ if (node === null)
255
+ return 0;
256
+ var left = node.left === null ? -1 : calcHeight(node.left);
257
+ var right = node.right === null ? -1 : calcHeight(node.right);
258
+ var max = left > right ? left : right;
259
+ return max + 1;
260
+ };
261
+ if (this._head === null) {
262
+ return 0;
263
+ }
264
+ else {
265
+ return calcHeight(this._head) + 1;
266
+ }
267
+ };
268
+ return BinarySearchTree;
269
+ }(AbstractBinaryTree_1.default));
270
+ exports.default = BinarySearchTree;
271
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQmluYXJ5U2VhcmNoVHJlZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9kYXRhLXN0cnVjdHVyZXMvQmluYXJ5VHJlZS9CaW5hcnlTZWFyY2hUcmVlL0JpbmFyeVNlYXJjaFRyZWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7O0FBQ0EsOEVBQTZFO0FBRTdFLCtFQUEwRTtBQUMxRSx1REFBa0Q7QUFDbEQsMkNBQXNDO0FBQ3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LENBQUMsQ0FBQztTQUNuQztJQUNILENBQUM7SUFDSCx1QkFBQztBQUFELENBQUMsQUFuUkQsQ0FBaUQsNEJBQWtCLEdBbVJsRSJ9
@@ -0,0 +1,16 @@
1
+ import BinarySearchNode from "../BinarySearchTree/BinarySearchNode";
2
+ export default class RandBinarySearchNode<T> extends BinarySearchNode<T> {
3
+ private _rank;
4
+ protected _left: RandBinarySearchNode<T> | null;
5
+ protected _right: RandBinarySearchNode<T> | null;
6
+ protected _parent: RandBinarySearchNode<T> | null;
7
+ constructor(initialData: T);
8
+ get rank(): number;
9
+ set rank(value: number);
10
+ get left(): RandBinarySearchNode<T> | null;
11
+ set left(value: RandBinarySearchNode<T> | null);
12
+ get right(): RandBinarySearchNode<T> | null;
13
+ set right(value: RandBinarySearchNode<T> | null);
14
+ get parent(): RandBinarySearchNode<T> | null;
15
+ set parent(value: RandBinarySearchNode<T> | null);
16
+ }
@@ -0,0 +1,70 @@
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
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ var BinarySearchNode_1 = require("../BinarySearchTree/BinarySearchNode");
17
+ var RandBinarySearchNode = /** @class */ (function (_super) {
18
+ __extends(RandBinarySearchNode, _super);
19
+ function RandBinarySearchNode(initialData) {
20
+ var _this = _super.call(this, initialData) || this;
21
+ _this._rank = 0;
22
+ _this._left = null;
23
+ _this._right = null;
24
+ _this._parent = null;
25
+ return _this;
26
+ }
27
+ Object.defineProperty(RandBinarySearchNode.prototype, "rank", {
28
+ get: function () {
29
+ return this._rank;
30
+ },
31
+ set: function (value) {
32
+ this._rank = value;
33
+ },
34
+ enumerable: false,
35
+ configurable: true
36
+ });
37
+ Object.defineProperty(RandBinarySearchNode.prototype, "left", {
38
+ get: function () {
39
+ return this._left;
40
+ },
41
+ set: function (value) {
42
+ this._left = value;
43
+ },
44
+ enumerable: false,
45
+ configurable: true
46
+ });
47
+ Object.defineProperty(RandBinarySearchNode.prototype, "right", {
48
+ get: function () {
49
+ return this._right;
50
+ },
51
+ set: function (value) {
52
+ this._right = value;
53
+ },
54
+ enumerable: false,
55
+ configurable: true
56
+ });
57
+ Object.defineProperty(RandBinarySearchNode.prototype, "parent", {
58
+ get: function () {
59
+ return this._parent;
60
+ },
61
+ set: function (value) {
62
+ this._parent = value;
63
+ },
64
+ enumerable: false,
65
+ configurable: true
66
+ });
67
+ return RandBinarySearchNode;
68
+ }(BinarySearchNode_1.default));
69
+ exports.default = RandBinarySearchNode;
70
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmFuZEJpbmFyeVNlYXJjaE5vZGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvZGF0YS1zdHJ1Y3R1cmVzL0JpbmFyeVRyZWUvUmFuZEJpbmFyeVNlYXJjaFRyZWUvUmFuZEJpbmFyeVNlYXJjaE5vZGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7O0FBQUEseUVBQW9FO0FBRXBFO0lBQXFELHdDQUFtQjtJQU10RSw4QkFBbUIsV0FBYztRQUFqQyxZQUNFLGtCQUFNLFdBQVcsQ0FBQyxTQUtuQjtRQUpDLEtBQUksQ0FBQyxLQUFLLEdBQUcsQ0FBQyxDQUFDO1FBQ2YsS0FBSSxDQUFDLEtBQUssR0FBRyxJQUFJLENBQUM7UUFDbEIsS0FBSSxDQUFDLE1BQU0sR0FBRyxJQUFJLENBQUM7UUFDbkIsS0FBSSxDQUFDLE9BQU8sR0FBRyxJQUFJLENBQUM7O0lBQ3RCLENBQUM7SUFFRCxzQkFBVyxzQ0FBSTthQUFmO1lBQ0UsT0FBTyxJQUFJLENBQUMsS0FBSyxDQUFDO1FBQ3BCLENBQUM7YUFFRCxVQUFnQixLQUFhO1lBQzNCLElBQUksQ0FBQyxLQUFLLEdBQUcsS0FBSyxDQUFDO1FBQ3JCLENBQUM7OztPQUpBO0lBTUQsc0JBQVcsc0NBQUk7YUFBZjtZQUNFLE9BQU8sSUFBSSxDQUFDLEtBQUssQ0FBQztRQUNwQixDQUFDO2FBRUQsVUFBZ0IsS0FBcUM7WUFDbkQsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7UUFDckIsQ0FBQzs7O09BSkE7SUFNRCxzQkFBVyx1Q0FBSzthQUFoQjtZQUNFLE9BQU8sSUFBSSxDQUFDLE1BQU0sQ0FBQztRQUNyQixDQUFDO2FBRUQsVUFBaUIsS0FBcUM7WUFDcEQsSUFBSSxDQUFDLE1BQU0sR0FBRyxLQUFLLENBQUM7UUFDdEIsQ0FBQzs7O09BSkE7SUFNRCxzQkFBVyx3Q0FBTTthQUFqQjtZQUNFLE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQztRQUN0QixDQUFDO2FBRUQsVUFBa0IsS0FBcUM7WUFDckQsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7UUFDdkIsQ0FBQzs7O09BSkE7SUFLSCwyQkFBQztBQUFELENBQUMsQUE3Q0QsQ0FBcUQsMEJBQWdCLEdBNkNwRSJ9
@@ -0,0 +1,57 @@
1
+ import { FnCompareTwo } from "../../../types/FnCompareTwo";
2
+ import RandBinarySearchNode from "./RandBinarySearchNode";
3
+ import BinarySearchTree from "../BinarySearchTree/BinarySearchTree";
4
+ /**
5
+ * Randomized binary search tree implementation
6
+ */
7
+ export default class RandBinarySearchTree<T> extends BinarySearchTree<T> {
8
+ /**
9
+ * Override types
10
+ */
11
+ protected _head: RandBinarySearchNode<T> | null;
12
+ /**
13
+ * @inheritDoc
14
+ */
15
+ constructor(fnCompare?: FnCompareTwo<T>);
16
+ /**
17
+ * Will update node rank by summing left and right subtrees tanks and itself rank (1)
18
+ */
19
+ private updateRank;
20
+ /**
21
+ * Will set rank and parent attributes and update tree length
22
+ */
23
+ private addCreatedNode;
24
+ /**
25
+ * Will rotate node to the right side
26
+ */
27
+ private rotateNodeRight;
28
+ /**
29
+ * Will rotate node to the left side
30
+ */
31
+ private rotateNodeLeft;
32
+ /**
33
+ * @inheritDoc
34
+ */
35
+ protected join(treeLeft: RandBinarySearchNode<T> | null, treeRight: RandBinarySearchNode<T> | null): RandBinarySearchNode<T> | null;
36
+ /**
37
+ * @inheritDoc
38
+ */
39
+ protected updateLeftRightParents(node: RandBinarySearchNode<T>): void;
40
+ /**
41
+ * @inheritDoc
42
+ */
43
+ protected insertToRoot(createdNode: RandBinarySearchNode<T>, fromNode?: RandBinarySearchNode<T>): void;
44
+ /**
45
+ * @inheritDoc
46
+ */
47
+ protected insertRandomly(createdNode: RandBinarySearchNode<T>): void;
48
+ /**
49
+ * @inheritDoc
50
+ */
51
+ insert(value: T): void;
52
+ /**
53
+ * @inheritDoc
54
+ */
55
+ delete(value: T): void;
56
+ length(): number;
57
+ }