| @@ 240-250 (lines=11) @@ | ||
| 237 | * @param DataStructures\Trees\Nodes\BSTNode $node the start point. |
|
| 238 | * @return DataStructures\Trees\Nodes\BSTNode|null the minimum node. |
|
| 239 | */ |
|
| 240 | private function getMinNode(BinaryNodeInterface $node = null) { |
|
| 241 | if($node === null) { |
|
| 242 | return null; |
|
| 243 | } |
|
| 244 | ||
| 245 | while($node->left !== null) { |
|
| 246 | $node = $node->left; |
|
| 247 | } |
|
| 248 | ||
| 249 | return $node; |
|
| 250 | } |
|
| 251 | ||
| 252 | /** |
|
| 253 | * Returns the maximum node from a given node in position X. |
|
| @@ 258-268 (lines=11) @@ | ||
| 255 | * @param DataStructures\Trees\Nodes\BSTNode $node the start point. |
|
| 256 | * @return DataStructures\Trees\Nodes\BSTNode|null the maximum node. |
|
| 257 | */ |
|
| 258 | private function getMaxNode(BinaryNodeInterface $node = null) { |
|
| 259 | if($node === null) { |
|
| 260 | return null; |
|
| 261 | } |
|
| 262 | ||
| 263 | while($node->right !== null) { |
|
| 264 | $node = $node->right; |
|
| 265 | } |
|
| 266 | ||
| 267 | return $node; |
|
| 268 | } |
|
| 269 | ||
| 270 | /** |
|
| 271 | * Deletes the node with the minimum key and returns it. The most left and more bottom. |
|