| @@ 175-185 (lines=11) @@ | ||
| 172 | * @param DataStructures\Trees\Nodes\BSTNode $node the start point. |
|
| 173 | * @return DataStructures\Trees\Nodes\BSTNode|null the minimum node. |
|
| 174 | */ |
|
| 175 | private function getMinNode(BinaryNodeInterface $node = null) { |
|
| 176 | if($node === null) { |
|
| 177 | return null; |
|
| 178 | } |
|
| 179 | ||
| 180 | while($node->left !== null) { |
|
| 181 | $node = $node->left; |
|
| 182 | } |
|
| 183 | ||
| 184 | return $node; |
|
| 185 | } |
|
| 186 | ||
| 187 | /** |
|
| 188 | * Returns the maximum node from a given node in position X. |
|
| @@ 193-203 (lines=11) @@ | ||
| 190 | * @param DataStructures\Trees\Nodes\BSTNode $node the start point. |
|
| 191 | * @return DataStructures\Trees\Nodes\BSTNode|null the maximum node. |
|
| 192 | */ |
|
| 193 | private function getMaxNode(BinaryNodeInterface $node = null) { |
|
| 194 | if($node === null) { |
|
| 195 | return null; |
|
| 196 | } |
|
| 197 | ||
| 198 | while($node->right !== null) { |
|
| 199 | $node = $node->right; |
|
| 200 | } |
|
| 201 | ||
| 202 | return $node; |
|
| 203 | } |
|
| 204 | ||
| 205 | /** |
|
| 206 | * Deletes the node with the minimum key and returns it. The most left and more bottom. |
|