|
8 | 8 | /** |
9 | 9 | * A node of the tree |
10 | 10 | * |
| 11 | + * @class |
11 | 12 | * @public |
12 | 13 | * @constructor |
13 | | - * @param {number|string} Value of the node |
| 14 | + * @param {Number|String} Value of the node |
14 | 15 | * @param {Node} Left subling |
15 | 16 | * @param {Node} Right sibling |
16 | 17 | * @param {Node} Parent of the node |
|
37 | 38 | * O(n) in the worst case. |
38 | 39 | * |
39 | 40 | * @public |
40 | | - * @param {number|string} Value |
| 41 | + * @param {Number|String} Value |
41 | 42 | * @param {[Node]} Current node |
42 | 43 | */ |
43 | 44 | BinaryTree.prototype.insert = function (value, current) { |
|
139 | 140 | * Finds a node by it's value. Average runtime complexity O(log n) |
140 | 141 | * |
141 | 142 | * @public |
142 | | - * @param {number|string} Value of the node which should be found |
| 143 | + * @param {Number|String} Value of the node which should be found |
143 | 144 | */ |
144 | 145 | BinaryTree.prototype.find = function (value) { |
145 | 146 | return this._find(value, this._root); |
|
149 | 150 | * Finds a node by it's value in given sub-tree. Average runtime complexity: O(log n). |
150 | 151 | * |
151 | 152 | * @private |
152 | | - * @param {number|string} Value of the node which should be found |
| 153 | + * @param {Number|String} Value of the node which should be found |
153 | 154 | * @param {Node} Current node to be checked |
154 | 155 | */ |
155 | 156 | BinaryTree.prototype._find = function (value, current) { |
156 | 157 | if (!current) |
157 | 158 | return null; |
158 | | - |
| 159 | + |
159 | 160 | if (current.value === value) |
160 | 161 | return current; |
161 | | - |
| 162 | + |
162 | 163 | if (current.value > value) |
163 | 164 | return this._find(value, current._left); |
164 | | - |
| 165 | + |
165 | 166 | if (current.value < value) |
166 | 167 | return this._find(value, current._right); |
167 | | - |
| 168 | + |
168 | 169 | }; |
169 | 170 |
|
170 | 171 | /** |
|
226 | 227 | * |
227 | 228 | * @private |
228 | 229 | * @param {Node} Root of the sub-tree |
229 | | - * @param {[number|string]} Current minimum value of the sub-tree |
| 230 | + * @param {[Number|String]} Current minimum value of the sub-tree |
230 | 231 | * @returns {Node} The node with minimum value in the sub-tree |
231 | 232 | */ |
232 | 233 | BinaryTree.prototype._findMin = function (node, current) { |
|
243 | 244 | * |
244 | 245 | * @private |
245 | 246 | * @param {Node} Root of the sub-tree |
246 | | - * @param {[number|string]} Current maximum value of the sub-tree |
| 247 | + * @param {[Number|String]} Current maximum value of the sub-tree |
247 | 248 | * @returns {Node} The node with maximum value in the sub-tree |
248 | 249 | */ |
249 | 250 | BinaryTree.prototype._findMax = function (node, current) { |
|
0 commit comments