-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes.py
45 lines (33 loc) · 1.14 KB
/
nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class BinaryTreeNode:
def __init__(self,value):
self.value = value
self.leftChild = None
self.rightChild = None
self.parent = None
def getChildren(self):
children = [None,None]
if self.leftChild != None:
children[0] = self.leftChild
if self.rightChild != None:
children[1] = self.rightChild
return children
def getSibling(self):
if self.parent.leftChild.value == self.value:
return self.parent.leftChild
else:
return self.parent.rightChild
class RedBlackNode(BinaryTreeNode):
def __init__(self,value,colour):
BinaryTreeNode.__init__(self,value)
self.colour = colour
class AVLNode(BinaryTreeNode):
def __init__(self,value):
BinaryTreeNode.__init__(self,value)
self.height = None
#def
def nodeSwap(node1,node2):
"""Swaps node1 and node2sdf"""
node1.value, node2.value = node2.value, node1.value
if __name__ == "__main__":
node = RedBlackNode(5,'r')
print node.value,node.colour