Home /
Expert Answers /
Computer Science /
python-nbsp-class-binarytree-create-and-submit-your-own-class-binarytree-that-implements-the-bin-pa548
(Solved): Python
Class BinaryTree Create and submit your own class BinaryTree that implements the Bin ...
Python
Class BinaryTree Create and submit your own class BinaryTree that implements the Binary Tree ADT: 1. A constructor BinaryTree(rootObj) 2. insertLeft(newNode) 3. insertRight(newNode) 4. getRightChild() 5. getLeftChild() 6. getRootVal(): 7. setRootVal(obj) 8. ___str_0_) should return a string in the following format root [left[[]]]][right[[]]]]] where root, left, right are values of the root, its left child, and its right child respectively. If the children are missing, then they are represented as [], so if the root does not have children, then it should be shown as root[][]. You can use the code below to start on your implementation: class BinaryTree: def _-init__(self, rootobj): self.key = root0bj self.leftChild = None self.rightChild = None def insertleft(self, newNode): if self.leftChild == None: self.leftChild = BinaryTree(n else: t \( = \) BinaryTree(newNode) t.leftChild \( = \) self.leftChild self.leftChild \( =\mathrm{t} \) self.leftChild \( = \) BinaryTree(newNode) \( r=\operatorname{Bin} a-y) \) \( p r i n t(r) \) \( r \) \( r \). insertLeft ('b') \( r \).insertRight ('c') print( \( r \) ) r.getLeftChild(). insertLeft( ' \( d \) ') r. getleftChild(). inserthefth' (') ' r.getRightChild(). insertLeft('f') print \( (r) \) print(r.getRootVal()) print( (r. getLeftChild()) print(r.getRightChild()) The driver code should produce the following output: \( a[][] \) \( a[b[]]][c[][]] \) \( a[b[d][]][e[]]][c[f[][]][] \) \( a \) \( b[d[][]][e[][]] \)