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