Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PART 1 GENERAL TREES Helper function to be used in the findHeight() function In this part you will be implementing a general tree data structure

image text in transcribed

PART 1 GENERAL TREES Helper function to be used in the findHeight() function In this part you will be implementing a general tree data structure where each node of a tree can have any number of children nodes. Refer to tree.hpp which provides all the required definitions. Write your implementation in tree.cpp using the boiler code. void delete Tree(shared_ptr> currNode) Delete the entire tree. . Member Functions: Write implementation for the following methods as described here: bool deleteLeaf(T key) Delete node with given key if and only if it is a leaf node i.e. have no child. Doesn't delete the root node even if it is the only node in the tree. Returns true on success, false on failure. Tree(shared_ptr> root) Constructor shared_ptr> deleteLeafHelper (shared_ptr> curr Node, T key) Helper function to delete the leaf node. shared_ptr> findKey(T key) Finds the node with the given key and returns a pointer to that node. NULL is returned if the key doesn't exist. shared_ptr> findKeyHelper (shared_ptr> currNode, I key) Helper function to be used in findkey (T key) function bool insertChild(shared_ptr> newNode, T key) Inserts the given node as the child of the given key. Returns true if insertion is successful and false if key doesn't exist. Insertion should also fail if another node with the same key as the new node already exists i.e. duplicates are not allowed. If the node at the given key already has children, the new node must be added to the tail of the children of that node. vector>> getAllChildren(T key) Returns all the children of the node with the given key. Should return an empty vector in case the node has no child or key doesn't exist. int findHeight() Returns the height of the tree

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

1. Evaluate the following integral. X +51 +7 X +5 X +1+1 + 512 + 5

Answered: 1 week ago