fix tests

This commit is contained in:
Dennis Eichhorn 2023-10-24 20:46:00 +00:00
parent ec49bf2dc1
commit d22f0a6d18

View File

@ -9,6 +9,7 @@
* @license OMS License 2.0 * @license OMS License 2.0
* @version 1.0.0 * @version 1.0.0
* @link https://jingga.app * @link https://jingga.app
* @link https://github.com/PetarV-/Algorithms/blob/master/Data%20Structures/Binary%20Search%20Tree.cpp
*/ */
declare(strict_types=1); declare(strict_types=1);
@ -229,19 +230,19 @@ class BinarySearchTree
public function delete(Node $node) : void public function delete(Node $node) : void
{ {
if ($node->left === null && $node->right === null) { if ($node->left === null && $node->right === null) {
if ($node->parent !== null) { if ($node->parent === null) {
if ($node->parent->left !== null return;
&& $node->parent->left->root?->compare($node->data) === 0
) {
$node->parent->left = null;
} elseif ($node->parent->right !== null
&& $node->parent->right->root?->compare($node->data) === 0
) {
$node->parent->right = null;
}
} }
//$node = null; if ($node->parent->left !== null
&& $node->parent->left->root?->compare($node->data) === 0
) {
$node->parent->left = null;
} elseif ($node->parent->right !== null
&& $node->parent->right->root?->compare($node->data) === 0
) {
$node->parent->right = null;
}
return; return;
} }