Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 - Accept simple entries such as name, and phone number 2 - Store the address book entries in a form of a Binary tree
1 - Accept simple entries such as name, and phone number 2 - Store the address book entries in a form of a Binary tree by inserting the entries, you will have to modify the current implementation to accept strings 3 - Upon startup, load the stored phone info from the phonebook file 4 - Display phone numbers info in a sorted order, limit the entries to few
BinaryTree,h: \#ifndef BINARYTREE_H \#define BINARYTREE_H \#include using namespace std; // Stack template template class BinaryTree \{ private: struct TreeNode \{ T value: // The value in the node TreeNode left; // Pointer to left child node TreeNode right; // Pointer to right child node \} TreeNode root; // Pointer to the root node // Private member functions void insert(TreeNode &, TreeNode & ); void destroySubTree(TreeNode * ); void deleteNode(T, TreeNode *\&); void makeDeletion(TreeNode *\&); void displaylnOrder(TreeNode ) const; void displayPreOrder(TreeNode * * const; void displayPostOrder(TreeNode * ) const; public: // Constructor BinaryTree() \{ root = nullptr; } // Destructor BinaryTree() { destroySubTree(root); } // Binary tree operations void insertNode(T); bool searchNode(T); void remove(T); void displaylnOrder() const \{ displaylnOrder(root); } void displayPreOrder() const { displayPreOrder(root); } void displayPostOrder() const { displayPostOrder(root); } 3; template else if (newNode->value > value) insert(nodePtr->left, newNode); // Search the left branch else insert(nodePtr->right, newNode); // Search the right branch 3 // insertNode creates a new node to hold num as its value, and passes it to the insert function. template void BinaryTree :-insertNode(T item) \{ TreeNode newNode = nullptr; // Pointer to a new node. // Create a new node and store num in it. newNode = new TreeNode; newNode->value = item; newNode > left = newNode > right = nullptr; // Insert the node. insert(root, newNode); \} // destroysubTree is called by the destructor. It deletes all nodes in the tree. template class T> if (nodePtr->left) destroySubTree(nodePtr->left); if (nodePtr->right) destroySubTree(nodePtr->right); delete nodePtr; \} // searchNode determines if a value is present in // the tree. If so, the function returns true. // Otherwise, it returns false. template bool BinaryTree
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started