Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SelfBalancingTree updated #189

Merged
merged 1 commit into from
Mar 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pydatastructs/trees/binary_trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ def _right_rotate(self, j, k):
self.tree[self.tree[k].parent].left = k
self.tree[j].parent = k
self.tree[k].right = j
kp = self.tree[k].parent
if kp is None:
self.root_idx = k

def _left_right_rotate(self, j, k):
i = self.tree[k].right
Expand Down Expand Up @@ -617,6 +620,9 @@ def _left_rotate(self, j, k):
self.tree[self.tree[k].parent].right = k
self.tree[j].parent = k
self.tree[k].left = j
kp = self.tree[k].parent
if kp is None:
self.root_idx = k

class AVLTree(SelfBalancingBinaryTree):
"""
Expand Down Expand Up @@ -645,9 +651,6 @@ def _right_rotate(self, j, k):
super(AVLTree, self)._right_rotate(j, k)
self.tree[j].height = max(self.left_height(self.tree[j]),
self.right_height(self.tree[j])) + 1
kp = self.tree[k].parent
if kp is None:
self.root_idx = k
if self.is_order_statistic:
self.tree[j].size = (self.left_size(self.tree[j]) +
self.right_size(self.tree[j]) + 1)
Expand Down Expand Up @@ -682,9 +685,6 @@ def _left_rotate(self, j, k):
self.right_height(self.tree[j])) + 1
self.tree[k].height = max(self.left_height(self.tree[k]),
self.right_height(self.tree[k])) + 1
kp = self.tree[k].parent
if kp is None:
self.root_idx = k
if self.is_order_statistic:
self.tree[j].size = (self.left_size(self.tree[j]) +
self.right_size(self.tree[j]) + 1)
Expand Down