@@ -180,32 +180,31 @@ private function insertFixup(Node $insertNode): void
180180 $ currentNode ->getParent ()->setColor (NodeColor::black ());
181181 $ uncleNode ->setColor (NodeColor::black ());
182182 $ grandfather ->setColor (NodeColor::red ());
183- $ currentNode = $ currentNode -> getParent ()-> getParent () ;
183+ $ currentNode = $ grandfather ;
184184 } else {
185185 if ($ currentNode === $ currentNode ->getParent ()->getRight ()) {
186186 $ currentNode = $ currentNode ->getParent ();
187187 $ this ->rotateLeft ($ currentNode );
188188 }
189189 $ currentNode ->getParent ()->setColor (NodeColor::black ());
190190 $ grandfather ->setColor (NodeColor::red ());
191- $ this ->rotateRight ($ currentNode -> getParent ()-> getParent () );
191+ $ this ->rotateRight ($ grandfather );
192192 }
193193 } else {
194- $ grandfather = $ currentNode ->getParent ()->getParent ();
195194 $ uncleNode = $ grandfather ->getLeft ();
196195 if ($ uncleNode ->getColor ()->isRed ()) {
197196 $ currentNode ->getParent ()->setColor (NodeColor::black ());
198197 $ uncleNode ->setColor (NodeColor::black ());
199198 $ grandfather ->setColor (NodeColor::red ());
200- $ currentNode = $ currentNode -> getParent ()-> getParent () ;
199+ $ currentNode = $ grandfather ;
201200 } else {
202201 if ($ currentNode === $ currentNode ->getParent ()->getLeft ()) {
203202 $ currentNode = $ currentNode ->getParent ();
204203 $ this ->rotateRight ($ currentNode );
205204 }
206205 $ currentNode ->getParent ()->setColor (NodeColor::black ());
207206 $ grandfather ->setColor (NodeColor::red ());
208- $ this ->rotateLeft ($ currentNode -> getParent ()-> getParent () );
207+ $ this ->rotateLeft ($ grandfather );
209208 }
210209 }
211210 }
@@ -385,7 +384,6 @@ private function treeSuccessor(Node $node): ?Node
385384 private function rotateLeft (Node $ x ): void
386385 {
387386 $ y = $ x ->getRight ();
388-
389387 $ x ->setRight ($ y ->getLeft ()); // b goes to x.right
390388
391389 if ($ y ->getLeft () !== $ this ->nilNode ) {
@@ -449,7 +447,10 @@ private function rotateRight(Node $y): void
449447 */
450448 private function treeWalk (): Iterator
451449 {
452- $ stack = [$ this ->root ];
450+ if ($ this ->root !== null ) {
451+ $ stack = [$ this ->root ];
452+ yield $ this ->root ;
453+ }
453454 while (!empty ($ stack )) {
454455 $ node = array_pop ($ stack );
455456 if ($ node ->getLeft () !== $ this ->nilNode ) {
0 commit comments