| @@ 202-212 (lines=11) @@ | ||
| 199 | * @param DataStructures\Trees\Nodes\BSTNode $node the start point. |
|
| 200 | * @return DataStructures\Trees\Nodes\BSTNode|null the minimum node. |
|
| 201 | */ |
|
| 202 | private function getMinNode(Node $node = null) { |
|
| 203 | if($node === null) { |
|
| 204 | return null; |
|
| 205 | } |
|
| 206 | ||
| 207 | while($node->left !== null) { |
|
| 208 | $node = $node->left; |
|
| 209 | } |
|
| 210 | ||
| 211 | return $node; |
|
| 212 | } |
|
| 213 | ||
| 214 | /** |
|
| 215 | * Gets the node with the maximum key. The most right and more bottom. |
|
| @@ 243-253 (lines=11) @@ | ||
| 240 | * @param DataStructures\Trees\Nodes\BSTNode $node the start point. |
|
| 241 | * @return DataStructures\Trees\Nodes\BSTNode|null the maximum node. |
|
| 242 | */ |
|
| 243 | private function getMaxNode(Node $node = null) { |
|
| 244 | if($node === null) { |
|
| 245 | return null; |
|
| 246 | } |
|
| 247 | ||
| 248 | while($node->right !== null) { |
|
| 249 | $node = $node->right; |
|
| 250 | } |
|
| 251 | ||
| 252 | return $node; |
|
| 253 | } |
|
| 254 | ||
| 255 | /** |
|
| 256 | * Deletes the node with the minimum key and returns it. The most left and more bottom. |
|