From d22f0a6d18c816a0657652cd65aa8cae751f2294 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 24 Oct 2023 20:46:00 +0000 Subject: [PATCH] fix tests --- Stdlib/Tree/BinarySearchTree.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 921eb99c0..6b03d4f17 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -9,6 +9,7 @@ * @license OMS License 2.0 * @version 1.0.0 * @link https://jingga.app + * @link https://github.com/PetarV-/Algorithms/blob/master/Data%20Structures/Binary%20Search%20Tree.cpp */ declare(strict_types=1); @@ -229,19 +230,19 @@ class BinarySearchTree public function delete(Node $node) : void { if ($node->left === null && $node->right === null) { - if ($node->parent !== 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; - } + if ($node->parent === null) { + return; } - //$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; }