Question
Using the given code, finish the rotate_right and rotate_left methods for the red black tree: class RBNode: def __init__(self, value): self.value = value self.left =
Using the given code, finish the rotate_right and rotate_left methods for the red black tree:
class RBNode:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
self.parent = None
self.colour = "R"
def get_uncle(self):
return
def is_leaf(self):
return self.left == None and self.right == None
def is_left_child(self):
return self == self.parent.left
def is_right_child(self):
return not self.is_left_child()
def is_red(self):
return self.colour == "R"
def is_black(self):
return not self.is_red()
def make_black(self):
self.colour = "B"
def make_red(self):
self.colour = "R"
def get_brother(self):
if self.parent.right == self:
return self.parent.left
return self.parent.right
def get_uncle(self):
return self.parent.get_brother()
def uncle_is_black(self):
if self.get_uncle() == None:
return True
return self.get_uncle().is_black()
def __str__(self):
return "(" + str(self.value) + "," + self.colour + ")"
def __repr__(self):
return "(" + str(self.value) + "," + self.colour + ")"
def rotate_right(self):
#TODO
def rotate_left(self):
#TODO
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started