Fix my code: code: import sys class Queue(object): def…
Question Fix my code: code: import sys class Queue(object): def… Image transcription textLeft Sum of BST Imagine you are looking at the left side of a binary search tree. The left-side-view nodes arenodes that are of the left-most node at each level. Return the sum of all the left-side-view nodes. Exampleinput: 15 10 20 9 30 Output: 34 Explanation: Input: A sequence of integers representing the BST … Show more… Show more Fix my code:code: import sysclass Queue(object): def __init__(self): self.queue = [] # add an item to the end of the queue def enqueue(self, item): self.queue.append(item) # remove an item from the beginning of the queue def dequeue(self): return (self.queue.pop(0)) # check if the queue is empty def is_empty(self): return (len(self.queue) == 0) # return the size of the queue def size(self): return (len(self.queue))class Node (object): def __init__ (self, data): self.data = data self.lchild = None self.rchild = Noneclass Tree (object): def __init__ (self): self.root = None # insert data into the tree def insert (self, data): new_node = Node (data) if (self.root == None): self.root = new_node return else: current = self.root parent = self.root while (current != None): parent = current if (data < current.data): current = current.lchild else: current = current.rchild # found location now insert node if (data < parent.data): parent.lchild = new_node else: parent.rchild = new_node # ***There is no reason to change anything above this line*** def get_height (self): height = 0 current = self.root while(current != None): height = height + 1 currrent = current.lchild return height def get_level (self, level): node_count = 1 current = self.root while(level !=0): if(node_count%2 !=0): current = current.lchild else: current = current.rchild level = level -1 node_count = node_count +1 return current.data # Returns an integer for the left sum of the BST def get_left_sum(self): total = 0 height = self.get_height() for i in range(height): total = total + self.get_level(i) return total# ***There is no reason to change anything below this line***def main(): # Create tree line = sys.stdin.readline() line = line.strip() line = line.split() tree_input = list (map (int, line)) # converts elements into ints tree = Tree() for i in tree_input: tree.insert(i) print(tree.get_left_sum())if __name__ == "__main__": main() Computer Science Engineering & Technology Python Programming CSCI 1310 Share QuestionEmailCopy link Comments (0)


