@@ 231-238 (lines=8) @@ | ||
228 | * @return DataStructures\Trees\Nodes\BSTNode|null the minimum node or |
|
229 | * null if the tree is empty. |
|
230 | */ |
|
231 | public function deleteMin(BinaryNodeInterface $node = null) { |
|
232 | $node = $this->getMinNode($node ?? $this->root); |
|
233 | if($node !== null) { |
|
234 | $this->_delete($node); |
|
235 | } |
|
236 | ||
237 | return $node; |
|
238 | } |
|
239 | ||
240 | /** |
|
241 | * Deletes the node with the maximum key and returns it. The most right and more bottom. |
|
@@ 247-254 (lines=8) @@ | ||
244 | * @return DataStructures\Trees\Nodes\BSTNode|null the maximum node or |
|
245 | * null if the tree is empty. |
|
246 | */ |
|
247 | public function deleteMax(BinaryNodeInterface $node = null) { |
|
248 | $node = $this->getMaxNode($node ?? $this->root); |
|
249 | if($node !== null) { |
|
250 | $this->_delete($node); |
|
251 | } |
|
252 | ||
253 | return $node; |
|
254 | } |
|
255 | ||
256 | /** |
|
257 | * Deletes the selected node if is not null and returns the node |