Skip to content

Commit 8e41aca

Browse files
committed
node now eses pythonproperties
1 parent d8cd33a commit 8e41aca

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

data_structures/AVL/AVL.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ class Node:
77

88
def __init__(self, label):
99
self.label = label
10-
self.left = None
11-
self.rigt = None
12-
self.parent = None
1310
self.height = 0
1411

1512
@property
@@ -23,7 +20,7 @@ def right(self, node):
2320

2421
@property
2522
def left(self):
26-
return self.parent
23+
return self.left
2724

2825
@left.setter
2926
def left(self, node):
@@ -48,6 +45,7 @@ def __init__(self):
4845

4946
def insert(self, value):
5047
node = Node(value)
48+
5149
if self.root is None:
5250
self.root = node
5351
self.root.height = 0
@@ -65,7 +63,7 @@ def insert(self, value):
6563
if node.label < curr_node.label:
6664
curr_node = curr_node.left
6765
else:
68-
curr_node = curr_node.rigt
66+
curr_node = curr_node.right
6967
else:
7068
if node.label < dad_node.label:
7169
dad_node.left = node
@@ -92,20 +90,20 @@ def rebalance(self, node):
9290

9391
if abs(height_left - height_right) > 1:
9492
if height_left > height_right:
95-
left_child = node.getRight()
93+
# left_child = node.getRight()
9694
if ():
9795
self.rotate_left(n)
9896
break
9997
else:
10098
self.double_rotate_right(n)
10199
break
102100
else:
103-
right_child = node.getRight()
101+
right_child = node.right
104102
if right_child is not None:
105-
h_right = (right_child.getRight().getHeight()
106-
if (right_child.getRight() is not None) else 0)
107-
h_left = (right_child.getLeft().getHeight()
108-
if (right_child.getLeft() is not None) else 0)
103+
h_right = (right_child.right.height
104+
if (right_child.right is not None) else 0)
105+
h_left = (right_child.left.height
106+
if (right_child.left is not None) else 0)
109107

110108
if (h_left > h_right):
111109
self.double_rotate_left(n)
@@ -119,9 +117,13 @@ def rotate_left(self, node):
119117
pass
120118

121119
def rotate_right(self, node):
122-
n = Node(node.getLabel())
123-
n.setRight(node.getRight())
124-
n.setLeft(Node(node.getParent().getLabel()))
120+
aux = node.parent
121+
node.parent = node
122+
node.left = aux
123+
124+
print(node.parent.label)
125+
print(node.parent.right.label)
126+
print(node.parent.left.label)
125127

126128
def double_rotate_left(self, node):
127129
self.rotate_right(node.getRight().getRight())

0 commit comments

Comments
 (0)