From 2b6e7b008d24d75a7acc32bbc7ae5090360e5198 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 Oct 2023 19:32:04 +0000 Subject: [PATCH] null fixes --- Stdlib/Tree/BinarySearchTree.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Stdlib/Tree/BinarySearchTree.php b/Stdlib/Tree/BinarySearchTree.php index 4a171d881..885ba1123 100644 --- a/Stdlib/Tree/BinarySearchTree.php +++ b/Stdlib/Tree/BinarySearchTree.php @@ -249,15 +249,15 @@ class BinarySearchTree if ($node->parent->left !== null && $node->parent->left->root?->compare($node->data) === 0 ) { - $node->parent->left = $temp->tree; + $node->parent->left = $temp?->tree; } elseif ($node->parent->right !== null && $node->parent->right->root?->compare($node->data) === 0 ) { - $node->parent->right = $temp->tree; + $node->parent->right = $temp?->tree; } } - $temp->parent = $node->parent; + $temp->parent = $node?->parent; $node = null; @@ -270,21 +270,20 @@ class BinarySearchTree if ($node->parent->left !== null && $node->parent->left->root?->compare($node->data) === 0 ) { - $node->parent->left = $temp->tree; + $node->parent->left = $temp?->tree; } elseif ($node->parent->right !== null && $node->parent->right->root?->compare($node->data) === 0 ) { - $node->parent->right = $temp->tree; + $node->parent->right = $temp?->tree; } } - $temp->parent = $node->parent; + $temp->parent = $node?->parent; $node = null; return; - } else { - $temp = $this->successor($node); + } elseif (($temp = $this->successor($node)) !== null) { $node->key = $temp->key; $node->data = $temp->data;