Question: Python 3.x changing starter code: What I understand from this question is that I have some starter code that I need to change to work

Python 3.x changing starter code:

Python 3.x changing starter code: What I understand from this question is

What I understand from this question is that I have some starter code that I need to change to work with KVTreenodes which are classes I cannot change the KVTreenode file which must be imported. I also have a testcase to make sure that it's working but since it is so long I'll post it on pastebin(https://pastebin.com/u7zPyRfB)

Here is the starter Code:

import KVTreeNode as TN  def member_prim(tnode, key): """  Purpose:  Check if value is stored in the binary search tree.  Preconditions:  :param tnode: a KVTreeNode with the BST property  :param key: a key  Postconditions:  none  :return: a pair True, value if key is in the tree  a pair False, None if the key is not in the tree  """  if tnode is None: return False, None elif tnode.key is key: return True, tnode.value elif key """  Insert a new key,value into the binary search tree.  Preconditions:  :param tnode: a KVTreeNode with the BST property  :param key: a key  Postconditions:  If the key is not already in the tree, it is added.  If the key is already in the tree, the old value is replaced  with the given value.  Return  :return: tuple (flag, tree)  flag is True if insertion succeeded;  tree contains the new key-value  flag is False if the value is already in the tree,  the value stored with the key is changed  """   return False, None def delete_prim(tnode, key): """  Delete a value from the binary search tree.  Preconditions:  :param tnode: a KVTreeNode with the BST property  :param key: a key  Postconditions:  If the key is in the tree, it is deleted. The tree  retains the binary search tree property.  If the key is not there, there is no change to the tree.  Return  :return: tuple (flag, tree)  flag is True if deletion succeeded;  tree is the resulting without the value  flag is False if the value was not in the tree,  tree returned unchanged  """   return False, None 

KVTreenode.py

# Defines the kv tree node ADT # # A KVTreeNode is a simple container with four pieces of # information: # key: the key for the node # value: the contained information # left: a reference to another KVTreeNode, or None # right: a reference to another KVTreeNode, or None # Implementation notes: # This ADT implementation uses a Python class class KVTreeNode(object): def __init__(self, key, value, left=None, right=None): """  Create a new KVTreeNode for the given data.  Pre-conditions:  key: A key used to identify the node  value: Any data value to be stored in the KVTreeNode  left: Another KVTreeNode (or None, by default)  right: Another KVTreeNode (or None, by default)  """  self.value = value self.left = left self.right = right self.key = key

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!