Answered step by step
Verified Expert Solution
Question
1 Approved Answer
it is from c++. template // DataType : tree data item class BSTree // KeyType : key field { public: // Constructor BSTree() // Default
it is from c++.
template // DataType : tree data item class BSTree // KeyType : key field { public: // Constructor BSTree() // Default constructor - create empty tree by initializing root to NULL { } BSTree(const BSTreeProgramming Exercise 1 collection of related pieces of information that is organized for easy retrie .? Balance A database is a rela records shown below (from accounts.dat), for instance, form an accounts da Last name Record # Account ID First name James Marcus Maureern Debra Mary Bruce Johnson Wilson Albright Douglas Smith Gold Carlson Becker Edgar Trumarn 9217.23 5145256 6274 2843 4892 8837 1892 9523 3165 27.26 918.26 719.32 496.24 38685 6023 5290 8529 1144 Simon John George Ellen Donald 16110.68 Fairchild Williams 86.77 4114.26 10 Each record in the accounts database is assigned a record number based on that record's relative position within the database file. You could use a record number to retrieve a record directly, much as you can use an array index to reference an array data item directly. Record numbers are assigned by the database file mechanism and are not part of the account information. As a result, they are not meaningful to database users. These users require a different record retrieval mechanism, one that is based on an account ID (the key for the database) rather than a record number Retrievals based on account ID require an index that associates each account ID with the corresponding record number. You can implement this index using a binary search tree in which each data item contains the two fields: an account ID (the key) and a record number. struct IndexEntry Programming Exercise 1 collection of related pieces of information that is organized for easy retrie .? Balance A database is a rela records shown below (from accounts.dat), for instance, form an accounts da Last name Record # Account ID First name James Marcus Maureern Debra Mary Bruce Johnson Wilson Albright Douglas Smith Gold Carlson Becker Edgar Trumarn 9217.23 5145256 6274 2843 4892 8837 1892 9523 3165 27.26 918.26 719.32 496.24 38685 6023 5290 8529 1144 Simon John George Ellen Donald 16110.68 Fairchild Williams 86.77 4114.26 10 Each record in the accounts database is assigned a record number based on that record's relative position within the database file. You could use a record number to retrieve a record directly, much as you can use an array index to reference an array data item directly. Record numbers are assigned by the database file mechanism and are not part of the account information. As a result, they are not meaningful to database users. These users require a different record retrieval mechanism, one that is based on an account ID (the key for the database) rather than a record number Retrievals based on account ID require an index that associates each account ID with the corresponding record number. You can implement this index using a binary search tree in which each data item contains the two fields: an account ID (the key) and a record number. struct IndexEntry& other) // Copy constructor - use copy helper function for recursion. { } BSTree& operator= (const BSTree & other) // Overloaded assignment operator - use copyHelper for recursion { } void copyHelper(BSTreeNode *&newNode, const BSTreeNode *&sourceNode) //Use as helper function for recursion for assignment operator overloading and for copy constructor { } // Destructor ~BSTree() //Use destructor helper function to recursively delete all pointers to nodes { } void destructorHelper(BSTreeNode*& current) //Recursively delete all nodes in tree { } // Binary search tree manipulation operations void insert(const DataType& newDataItem) // Insert data item - Use insertHelper function to traverse the tree, comparing new value to current values in each node until the end of the tree is met, then insert the new node pointer. Also, stops if key is already in tree { } insertHelper(BSTreeNode*& currentNode, const DataType& newDataItem) //Traverses tree until appropriate spot is found for new key value. creates new node pointer and adds it to found position. if key is found in tree, overwrites dataItem containing that key with the new dataItem (in case the data item contains other variables that are different than what is currently contained in the tree at that node) { } bool retrieve(const KeyType& searchKey, DataType& searchDataItem) const // Retrieve data item //Searches for key in tree. If not found, return false. If found, copies that nodes dataItem into searchDataItem, and then returns true { } bool remove(const KeyType& deleteKey) // Remove data item //Searches through tree for "deleteKey" key. If not found, return false. If found, (via the deleteHelper function - (delete that node, shift all other nodes to the appropriate new location)), then return true { } void deleteHelper(BSTreeNode*& current, BSTreeNode*& trail) //If key is found in tree in the remove function, delete node, and shift all other nodes to the appropriate new location { } void writeKeys() const // Output keys //Use a recursive inorder function to read all nodes keys in ascending order { } void clear() // Clear tree, not delete it. So delete all nodes except the root, and set root to NULL, or use destructorHelper to delete entire tree, then reinitialize root to NULL { } // Binary search tree status operations bool isEmpty() const // Tree is empty //Return true or false based on if root is NULL or not, which indicates if the tree is empty or not { } protected: class BSTreeNode // Inner class: facilitator for the BSTree class { public: // Constructor BSTreeNode() { left = nullptr; right = nullptr; } // Data members DataType dataItem; // Binary search tree data item BSTreeNode *left, // Pointer to the left child *right; // Pointer to the right child }; // Data member BSTreeNode *root; // Pointer to the root node }; //I removed all functions that are not relevant yet, so you wouldnt get distracted while attempting these
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