Sign InNuggetsCoursesCodePadCheatsheet

Insert the Right Subtree

Complete the implementation of the method insert_right in the BinaryTree class.

class BinaryTree: def __init__(self, data=None, left=None, right=None): self.data = data self.left = left self.right = right def get_data(self): return self.data def get_left(self): return self.left def get_right(self): return self.right def set_data(self, data): self.data = data def insert_left(self, new_node): if self.left == None: self.left = BinaryTree(new_node) else: t = BinaryTree(new_node) t.left = self.left self.left = t def insert_right(self, new_node): r = BinaryTree('a') print(r.get_data()) print(r.get_left()) r.insert_left('b') print(r.get_left().get_data()) r.insert_right('c') print(r.get_right().get_data())
© CS Wonders·Home·About·Contact·Classes·Gallery·Glossary·Fun Facts