Inspect the BSTNode class declaration for a binary search tree node in BSTNode.h. The BSTNode class has private member variables for the key, parent pointer, left child pointer, and right child pointer. Accessor functions exist for each.
Added by Timothy L.
Step 1
h file. This declaration will define the structure of a node in a binary search tree. Show more…
Show all steps
Your feedback will help us improve your experience
Akash M and 60 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
CBST<ItemType>& operator=(const CBST<ItemType> &rhs);
Akash M.
C++ Program Write the function singleParent that returns the number of nodes in a binary tree that has only one child. Add this function to the class binaryTreeType and create a program to test this function. (Note: First create a binary search tree.)
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__() 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 = rootObj self.leftChild = None self.rightChild = None def insertLeft(self,newNode): if self.leftChild == None: self.leftChild = BinaryTree(newNode) else: t = BinaryTree(newNode) t.leftChild = self.leftChild self.leftChild = t if __name__ == '__main__': r = BinaryTree('a') print(r) r.insertLeft('b') r.insertRight('c') print(r) r.getLeftChild().insertLeft('d') r.getLeftChild().insertRight('e') 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[][]] c[f[][]][]
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD