Question: *Using python please comment code* class Node(object): # Node Class for Binary Search Tree. # A node has a parent, left child, and right child.

*Using python please comment code*

class Node(object): # Node Class for Binary Search Tree. # A node has a parent, left child, and right child. # A node also has data. # data should only be touched by accessor methods defined here # i.e., set* and get*

def __init__(self, data): self.__data = data self.__parent = None self.__leftChild = None self.__rightChild = None

def setData(self, data): self.__data = data

def setLeftChild(self, lc): self.__leftChild = lc

def setRightChild(self, rc): self.__rightChild = rc

def setParent(self, p): self.__parent = p

def getData(self): return self.__data def getLeftChild(self): return self.__leftChild def getRightChild(self): return self.__rightChild def getParent(self): return self.__parent

from Node import Node

------other file--------

class BST(object): def __init__(self): self.__root = None

def getRoot(self): # Private Method, can only be used inside of BST. return self.__root

def __findNode(self, data): # Private Method, can only be used inside of BST. # Search tree for a node whose data field is equal to data. # Return the Node object pass

def contains(self, data): # return True of node containing data is present in the tree. # otherwise, return False. pass

def insert(self, data): # Find the right spot in the tree for the new node # Make sure to check if anything is in the tree # Hint: if a node n is null, calling n.getData() will cause an error pass def delete(self, data): # Find the node to delete. # If the value specified by delete does not exist in the tree, then don't change the tree. # If you find the node and ... # a) The node has no children, just set it's parent's pointer to Null. # b) The node has one child, make the nodes parent point to its child. # c) The node has two children, replace it with its successor, and remove # successor from its previous location. # Recall: The successor of a node is the left-most node in the node's right subtree. # Hint: you may want to write a new method, findSuccessor() to find the successor when there are two children

return None

def __findSuccessor(self, aNode): pass

def traverse(self, order, top): # traverse the tree by printing out the node data for all node in a specified order

if top is not None: if order == "preorder": # your code here, remove pass pass elif order == "inorder": # your code here, remove pass pass

elif order == "postorder": # your code here, remove pass pass else: print("Error, order {} undefined".format(order))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!