File tree Expand file tree Collapse file tree
data_structures/binary_tree Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,14 +177,14 @@ def _splay(self, node: SplayNode) -> None:
177177 else :
178178 self ._rotate_left (grandparent )
179179 self ._rotate_left (parent )
180+ elif node is parent .left :
181+ # Zig-zag case: opposite directions (left child)
182+ self ._rotate_right (parent )
183+ self ._rotate_left (grandparent )
180184 else :
181- # Zig-zag case: opposite directions
182- if node is parent .left :
183- self ._rotate_right (parent )
184- self ._rotate_left (grandparent )
185- else :
186- self ._rotate_left (parent )
187- self ._rotate_right (grandparent )
185+ # Zig-zag case: opposite directions (right child)
186+ self ._rotate_left (parent )
187+ self ._rotate_right (grandparent )
188188
189189 def _find_node (self , value : Any ) -> SplayNode | None :
190190 """Find a node with the given value, splaying it to root if found."""
You can’t perform that action at this time.
0 commit comments